diff options
author | chai <chaifix@163.com> | 2019-04-02 08:47:15 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-04-02 08:47:15 +0800 |
commit | 250e30d73f09e9da2b5a81d0fbae63744ae12a73 (patch) | |
tree | 0f55daf334c073e1779d7a1284799a2056aad714 | |
parent | 66fe16dd5ed57ae958fc25158d0defae2e6fae6a (diff) |
*misc
332 files changed, 13191 insertions, 1260 deletions
diff --git a/Build/Asura.Editor/Asura.Editor.vcxproj b/Build/Asura.Editor/Asura.Editor.vcxproj index 11dd494..c582aac 100644 --- a/Build/Asura.Editor/Asura.Editor.vcxproj +++ b/Build/Asura.Editor/Asura.Editor.vcxproj @@ -123,6 +123,7 @@ <ClCompile Include="..\..\source\Asura.Editor\controls\hslider.cpp" /> <ClCompile Include="..\..\source\Asura.Editor\controls\hvslider.cpp" /> <ClCompile Include="..\..\source\Asura.Editor\controls\label.cpp" /> + <ClCompile Include="..\..\source\Asura.Editor\controls\menu_item.cpp" /> <ClCompile Include="..\..\source\Asura.Editor\controls\panel.cpp" /> <ClCompile Include="..\..\source\Asura.Editor\controls\progress.cpp" /> <ClCompile Include="..\..\source\Asura.Editor\controls\radio_button.cpp" /> @@ -141,6 +142,7 @@ <ClInclude Include="..\..\source\Asura.Editor\controls\hslider.h" /> <ClInclude Include="..\..\source\Asura.Editor\controls\hvslider.h" /> <ClInclude Include="..\..\source\Asura.Editor\controls\label.h" /> + <ClInclude Include="..\..\source\Asura.Editor\controls\menu_item.h" /> <ClInclude Include="..\..\source\Asura.Editor\controls\panel.h" /> <ClInclude Include="..\..\source\Asura.Editor\controls\progress.h" /> <ClInclude Include="..\..\source\Asura.Editor\controls\radio_button.h" /> diff --git a/Build/Asura.Editor/Asura.Editor.vcxproj.filters b/Build/Asura.Editor/Asura.Editor.vcxproj.filters index 937f9a2..a87c4cb 100644 --- a/Build/Asura.Editor/Asura.Editor.vcxproj.filters +++ b/Build/Asura.Editor/Asura.Editor.vcxproj.filters @@ -63,6 +63,9 @@ <ClCompile Include="..\..\source\Asura.Editor\controls\binding\_button.cpp"> <Filter>controls\binding</Filter> </ClCompile> + <ClCompile Include="..\..\source\Asura.Editor\controls\menu_item.cpp"> + <Filter>controls</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\..\source\Asura.Editor\layout\horizontal_layout.h"> @@ -115,5 +118,8 @@ <ClInclude Include="..\..\source\Asura.Editor\controls\widget.h"> <Filter>controls</Filter> </ClInclude> + <ClInclude Include="..\..\source\Asura.Editor\controls\menu_item.h"> + <Filter>controls</Filter> + </ClInclude> </ItemGroup> </Project>
\ No newline at end of file diff --git a/Source/Asura.Editor/scripts/main.lua b/Source/Asura.Editor/scripts/main.lua deleted file mode 100644 index 76fab7a..0000000 --- a/Source/Asura.Editor/scripts/main.lua +++ /dev/null @@ -1,4 +0,0 @@ - ---༭ ---༭Asura.Editor/scriptsʵ - diff --git a/Source/Asura.Editor/scripts/scene_view.lua b/Source/Asura.Editor/scripts/scene_view.lua deleted file mode 100644 index b6097f3..0000000 --- a/Source/Asura.Editor/scripts/scene_view.lua +++ /dev/null @@ -1,4 +0,0 @@ --- 场景窗口 -local scene = AsuraEditor.Window.New("Window/Scene View") - - diff --git a/bin/win64/01-window.exe b/bin/win64/01-window.exe Binary files differnew file mode 100644 index 0000000..71ec490 --- /dev/null +++ b/bin/win64/01-window.exe diff --git a/bin/win64/SDL2.dll b/bin/win64/SDL2.dll Binary files differnew file mode 100644 index 0000000..a88528d --- /dev/null +++ b/bin/win64/SDL2.dll diff --git a/bin/win64/img.png b/bin/win64/img.png Binary files differnew file mode 100644 index 0000000..0d11f85 --- /dev/null +++ b/bin/win64/img.png diff --git a/build/3rd-party/glad/glad.vcxproj b/build/3rd-party/glad/glad.vcxproj index 71c6cc4..a1579f4 100644 --- a/build/3rd-party/glad/glad.vcxproj +++ b/build/3rd-party/glad/glad.vcxproj @@ -39,13 +39,13 @@ <CharacterSet>MultiByte</CharacterSet> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> - <ConfigurationType>Application</ConfigurationType> + <ConfigurationType>StaticLibrary</ConfigurationType> <UseDebugLibraries>true</UseDebugLibraries> <PlatformToolset>v141</PlatformToolset> <CharacterSet>MultiByte</CharacterSet> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> - <ConfigurationType>Application</ConfigurationType> + <ConfigurationType>StaticLibrary</ConfigurationType> <UseDebugLibraries>false</UseDebugLibraries> <PlatformToolset>v141</PlatformToolset> <WholeProgramOptimization>true</WholeProgramOptimization> @@ -69,7 +69,12 @@ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> </ImportGroup> <PropertyGroup Label="UserMacros" /> - <PropertyGroup /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <OutDir>$(SolutionDir)..\Bin\win64</OutDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <OutDir>$(SolutionDir)..\Bin\win64</OutDir> + </PropertyGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ClCompile> <WarningLevel>Level3</WarningLevel> diff --git a/build/Asura.Editor/Asura.Editor.vcxproj b/build/Asura.Editor/Asura.Editor.vcxproj index 11dd494..c582aac 100644 --- a/build/Asura.Editor/Asura.Editor.vcxproj +++ b/build/Asura.Editor/Asura.Editor.vcxproj @@ -123,6 +123,7 @@ <ClCompile Include="..\..\source\Asura.Editor\controls\hslider.cpp" /> <ClCompile Include="..\..\source\Asura.Editor\controls\hvslider.cpp" /> <ClCompile Include="..\..\source\Asura.Editor\controls\label.cpp" /> + <ClCompile Include="..\..\source\Asura.Editor\controls\menu_item.cpp" /> <ClCompile Include="..\..\source\Asura.Editor\controls\panel.cpp" /> <ClCompile Include="..\..\source\Asura.Editor\controls\progress.cpp" /> <ClCompile Include="..\..\source\Asura.Editor\controls\radio_button.cpp" /> @@ -141,6 +142,7 @@ <ClInclude Include="..\..\source\Asura.Editor\controls\hslider.h" /> <ClInclude Include="..\..\source\Asura.Editor\controls\hvslider.h" /> <ClInclude Include="..\..\source\Asura.Editor\controls\label.h" /> + <ClInclude Include="..\..\source\Asura.Editor\controls\menu_item.h" /> <ClInclude Include="..\..\source\Asura.Editor\controls\panel.h" /> <ClInclude Include="..\..\source\Asura.Editor\controls\progress.h" /> <ClInclude Include="..\..\source\Asura.Editor\controls\radio_button.h" /> diff --git a/build/Asura.Editor/Asura.Editor.vcxproj.filters b/build/Asura.Editor/Asura.Editor.vcxproj.filters index 937f9a2..a87c4cb 100644 --- a/build/Asura.Editor/Asura.Editor.vcxproj.filters +++ b/build/Asura.Editor/Asura.Editor.vcxproj.filters @@ -63,6 +63,9 @@ <ClCompile Include="..\..\source\Asura.Editor\controls\binding\_button.cpp"> <Filter>controls\binding</Filter> </ClCompile> + <ClCompile Include="..\..\source\Asura.Editor\controls\menu_item.cpp"> + <Filter>controls</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\..\source\Asura.Editor\layout\horizontal_layout.h"> @@ -115,5 +118,8 @@ <ClInclude Include="..\..\source\Asura.Editor\controls\widget.h"> <Filter>controls</Filter> </ClInclude> + <ClInclude Include="..\..\source\Asura.Editor\controls\menu_item.h"> + <Filter>controls</Filter> + </ClInclude> </ItemGroup> </Project>
\ No newline at end of file diff --git a/build/Debug/01-window.exe b/build/Debug/01-window.exe Binary files differnew file mode 100644 index 0000000..2dcd77b --- /dev/null +++ b/build/Debug/01-window.exe diff --git a/build/modules/asura-core/asura-core.vcxproj b/build/modules/asura-core/asura-core.vcxproj index e539e72..e9b1c06 100644 --- a/build/modules/asura-core/asura-core.vcxproj +++ b/build/modules/asura-core/asura-core.vcxproj @@ -39,13 +39,13 @@ <CharacterSet>MultiByte</CharacterSet> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> - <ConfigurationType>Application</ConfigurationType> + <ConfigurationType>StaticLibrary</ConfigurationType> <UseDebugLibraries>true</UseDebugLibraries> <PlatformToolset>v141</PlatformToolset> <CharacterSet>MultiByte</CharacterSet> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> - <ConfigurationType>Application</ConfigurationType> + <ConfigurationType>StaticLibrary</ConfigurationType> <UseDebugLibraries>false</UseDebugLibraries> <PlatformToolset>v141</PlatformToolset> <WholeProgramOptimization>true</WholeProgramOptimization> @@ -69,7 +69,12 @@ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> </ImportGroup> <PropertyGroup Label="UserMacros" /> - <PropertyGroup /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <OutDir>$(SolutionDir)..\Bin\win64</OutDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <OutDir>$(SolutionDir)..\Bin\win64</OutDir> + </PropertyGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ClCompile> <WarningLevel>Level3</WarningLevel> @@ -126,8 +131,6 @@ <ClCompile Include="..\..\..\source\modules\asura-core\graphics\binding\_color.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\binding\_color32.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\binding\_image.cpp" /> - <ClCompile Include="..\..\..\source\modules\asura-core\graphics\binding\_image_data.cpp" /> - <ClCompile Include="..\..\..\source\modules\asura-core\graphics\binding\_image_decode_task.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\binding\_mesh2d.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\binding\_shader.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\binding\_sprite_batch.cpp" /> @@ -138,33 +141,35 @@ <ClCompile Include="..\..\..\source\modules\asura-core\graphics\gif.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\gl.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\image.cpp" /> - <ClCompile Include="..\..\..\source\modules\asura-core\graphics\image_data.cpp" /> - <ClCompile Include="..\..\..\source\modules\asura-core\graphics\image_decode_task.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\mesh2d.cpp" /> - <ClCompile Include="..\..\..\source\modules\asura-core\graphics\mesh2d_data.cpp" /> - <ClCompile Include="..\..\..\source\modules\asura-core\graphics\png_decoder.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\quad.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\render_target.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\shader.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\shape.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\sprite_batch.cpp" /> - <ClCompile Include="..\..\..\source\modules\asura-core\graphics\stb_decoder.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\texture.cpp" /> + <ClCompile Include="..\..\..\source\modules\asura-core\image\binding\_image_data.cpp" /> + <ClCompile Include="..\..\..\source\modules\asura-core\image\binding\_image_decode_task.cpp" /> + <ClCompile Include="..\..\..\source\modules\asura-core\image\image_data.cpp" /> + <ClCompile Include="..\..\..\source\modules\asura-core\image\image_decode_task.cpp" /> + <ClCompile Include="..\..\..\source\modules\asura-core\image\png_decoder.cpp" /> + <ClCompile Include="..\..\..\source\modules\asura-core\image\stb_decoder.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\input\clipboard.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\input\cursor.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\input\cursor_impl_sdl.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\input\equeue.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\input\keyboard.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\input\mouse.cpp" /> + <ClCompile Include="..\..\..\source\modules\asura-core\mesh\mesh2d_data.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\profiler\stats.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\threading\channel.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\threading\thread_ex.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-core\time\timer.cpp" /> - <ClCompile Include="..\..\..\source\modules\asura-core\wnd\binding\_window.cpp" /> - <ClCompile Include="..\..\..\source\modules\asura-core\wnd\window.cpp" /> - <ClCompile Include="..\..\..\source\modules\asura-core\wnd\window_impl_glew.cpp" /> - <ClCompile Include="..\..\..\source\modules\asura-core\wnd\window_impl_glut.cpp" /> - <ClCompile Include="..\..\..\source\modules\asura-core\wnd\window_impl_sdl.cpp" /> + <ClCompile Include="..\..\..\source\modules\asura-core\window\binding\_window.cpp" /> + <ClCompile Include="..\..\..\source\modules\asura-core\window\window.cpp" /> + <ClCompile Include="..\..\..\source\modules\asura-core\window\window_impl_glew.cpp" /> + <ClCompile Include="..\..\..\source\modules\asura-core\window\window_impl_glut.cpp" /> + <ClCompile Include="..\..\..\source\modules\asura-core\window\window_impl_sdl.cpp" /> </ItemGroup> <ItemGroup> <ClInclude Include="..\..\..\source\modules\asura-core\application.h" /> @@ -182,12 +187,7 @@ <ClInclude Include="..\..\..\source\modules\asura-core\graphics\gif.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\graphics\gl.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\graphics\image.h" /> - <ClInclude Include="..\..\..\source\modules\asura-core\graphics\image_data.h" /> - <ClInclude Include="..\..\..\source\modules\asura-core\graphics\image_decoder.h" /> - <ClInclude Include="..\..\..\source\modules\asura-core\graphics\image_decode_task.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\graphics\mesh2d.h" /> - <ClInclude Include="..\..\..\source\modules\asura-core\graphics\mesh2d_data.h" /> - <ClInclude Include="..\..\..\source\modules\asura-core\graphics\png_decoder.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\graphics\quad.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\graphics\render_state.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\graphics\render_target.h" /> @@ -195,8 +195,12 @@ <ClInclude Include="..\..\..\source\modules\asura-core\graphics\shader_source.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\graphics\shape.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\graphics\sprite_batch.h" /> - <ClInclude Include="..\..\..\source\modules\asura-core\graphics\stb_decoder.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\graphics\texture.h" /> + <ClInclude Include="..\..\..\source\modules\asura-core\image\image_data.h" /> + <ClInclude Include="..\..\..\source\modules\asura-core\image\image_decoder.h" /> + <ClInclude Include="..\..\..\source\modules\asura-core\image\image_decode_task.h" /> + <ClInclude Include="..\..\..\source\modules\asura-core\image\png_decoder.h" /> + <ClInclude Include="..\..\..\source\modules\asura-core\image\stb_decoder.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\input\clipboard.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\input\cursor.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\input\cursor_impl_sdl.h" /> @@ -209,21 +213,36 @@ <ClInclude Include="..\..\..\source\modules\asura-core\input\keyboard.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\input\mouse.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\input\event_manager.h" /> + <ClInclude Include="..\..\..\source\modules\asura-core\mesh\mesh2d_data.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\profiler\stats.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\threading\channel.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\threading\thread_ex.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\time\timer.h" /> <ClInclude Include="..\..\..\source\modules\asura-core\type.h" /> - <ClInclude Include="..\..\..\source\modules\asura-core\wnd\window.h" /> - <ClInclude Include="..\..\..\source\modules\asura-core\wnd\window_impl_glew.h" /> - <ClInclude Include="..\..\..\source\modules\asura-core\wnd\window_impl_glut.h" /> - <ClInclude Include="..\..\..\source\modules\asura-core\wnd\window_impl_sdl.h" /> + <ClInclude Include="..\..\..\source\modules\asura-core\window\window.h" /> + <ClInclude Include="..\..\..\source\modules\asura-core\window\window_impl_glew.h" /> + <ClInclude Include="..\..\..\source\modules\asura-core\window\window_impl_glut.h" /> + <ClInclude Include="..\..\..\source\modules\asura-core\window\window_impl_sdl.h" /> </ItemGroup> <ItemGroup> <None Include="..\..\..\source\modules\asura-core\font\string.inl" /> <None Include="..\..\..\source\modules\asura-core\font\utf.inl" /> <None Include="..\..\..\source\modules\asura-core\input\keys.h" /> </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\3rd-party\glad\glad.vcxproj"> + <Project>{c0ed7d78-570b-454a-b3b6-576fdcb43d69}</Project> + </ProjectReference> + <ProjectReference Include="..\..\3rd-party\SDL2\SDL2.vcxproj"> + <Project>{208b9cb8-2101-42a9-9502-0cf54912bc57}</Project> + </ProjectReference> + <ProjectReference Include="..\..\3rd-party\stb\stb.vcxproj"> + <Project>{6ba52bbb-8da5-4f51-be3f-1e49f5089498}</Project> + </ProjectReference> + <ProjectReference Include="..\asura-utils\asura-utils.vcxproj"> + <Project>{7d41093f-e356-4c5b-a25f-41779bf86e54}</Project> + </ProjectReference> + </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> diff --git a/build/modules/asura-core/asura-core.vcxproj.filters b/build/modules/asura-core/asura-core.vcxproj.filters index eb4b20c..0482ee1 100644 --- a/build/modules/asura-core/asura-core.vcxproj.filters +++ b/build/modules/asura-core/asura-core.vcxproj.filters @@ -22,14 +22,23 @@ <Filter Include="threading"> <UniqueIdentifier>{05477a0e-f70b-4606-ae96-82ef7a7b8a1d}</UniqueIdentifier> </Filter> - <Filter Include="wnd"> + <Filter Include="input\binding"> + <UniqueIdentifier>{66e43743-1be3-414a-9f3c-473d40613892}</UniqueIdentifier> + </Filter> + <Filter Include="image"> + <UniqueIdentifier>{5061f7d5-03a9-480a-83eb-35d9806abde3}</UniqueIdentifier> + </Filter> + <Filter Include="mesh"> + <UniqueIdentifier>{0a758ae6-91a0-462a-968f-aa3412a714ae}</UniqueIdentifier> + </Filter> + <Filter Include="window"> <UniqueIdentifier>{7a73607c-8da6-4865-a992-5c7c8764bd5a}</UniqueIdentifier> </Filter> - <Filter Include="wnd\binding"> + <Filter Include="window\binding"> <UniqueIdentifier>{139aa01b-d038-4361-9edd-f81d8ba37730}</UniqueIdentifier> </Filter> - <Filter Include="input\binding"> - <UniqueIdentifier>{66e43743-1be3-414a-9f3c-473d40613892}</UniqueIdentifier> + <Filter Include="image\binding"> + <UniqueIdentifier>{43e14e72-d4cb-47b8-b55c-7327a6fc0508}</UniqueIdentifier> </Filter> </ItemGroup> <ItemGroup> @@ -49,12 +58,6 @@ <ClCompile Include="..\..\..\source\modules\asura-core\graphics\mesh2d.cpp"> <Filter>graphics</Filter> </ClCompile> - <ClCompile Include="..\..\..\source\modules\asura-core\graphics\mesh2d_data.cpp"> - <Filter>graphics</Filter> - </ClCompile> - <ClCompile Include="..\..\..\source\modules\asura-core\graphics\png_decoder.cpp"> - <Filter>graphics</Filter> - </ClCompile> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\quad.cpp"> <Filter>graphics</Filter> </ClCompile> @@ -70,9 +73,6 @@ <ClCompile Include="..\..\..\source\modules\asura-core\graphics\sprite_batch.cpp"> <Filter>graphics</Filter> </ClCompile> - <ClCompile Include="..\..\..\source\modules\asura-core\graphics\stb_decoder.cpp"> - <Filter>graphics</Filter> - </ClCompile> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\texture.cpp"> <Filter>graphics</Filter> </ClCompile> @@ -107,12 +107,6 @@ <ClCompile Include="..\..\..\source\modules\asura-core\graphics\binding\_image.cpp"> <Filter>graphics\binding</Filter> </ClCompile> - <ClCompile Include="..\..\..\source\modules\asura-core\graphics\binding\_image_data.cpp"> - <Filter>graphics\binding</Filter> - </ClCompile> - <ClCompile Include="..\..\..\source\modules\asura-core\graphics\binding\_image_decode_task.cpp"> - <Filter>graphics\binding</Filter> - </ClCompile> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\binding\_mesh2d.cpp"> <Filter>graphics\binding</Filter> </ClCompile> @@ -131,30 +125,9 @@ <ClCompile Include="..\..\..\source\modules\asura-core\graphics\image.cpp"> <Filter>graphics</Filter> </ClCompile> - <ClCompile Include="..\..\..\source\modules\asura-core\graphics\image_data.cpp"> - <Filter>graphics</Filter> - </ClCompile> - <ClCompile Include="..\..\..\source\modules\asura-core\graphics\image_decode_task.cpp"> - <Filter>graphics</Filter> - </ClCompile> - <ClCompile Include="..\..\..\source\modules\asura-core\wnd\window.cpp"> - <Filter>wnd</Filter> - </ClCompile> - <ClCompile Include="..\..\..\source\modules\asura-core\wnd\window_impl_glew.cpp"> - <Filter>wnd</Filter> - </ClCompile> - <ClCompile Include="..\..\..\source\modules\asura-core\wnd\window_impl_glut.cpp"> - <Filter>wnd</Filter> - </ClCompile> - <ClCompile Include="..\..\..\source\modules\asura-core\wnd\window_impl_sdl.cpp"> - <Filter>wnd</Filter> - </ClCompile> <ClCompile Include="..\..\..\source\modules\asura-core\graphics\binding\_texture.cpp"> <Filter>graphics\binding</Filter> </ClCompile> - <ClCompile Include="..\..\..\source\modules\asura-core\wnd\binding\_window.cpp"> - <Filter>wnd\binding</Filter> - </ClCompile> <ClCompile Include="..\..\..\source\modules\asura-core\input\clipboard.cpp"> <Filter>input</Filter> </ClCompile> @@ -173,6 +146,42 @@ <ClCompile Include="..\..\..\source\modules\asura-core\input\equeue.cpp"> <Filter>input</Filter> </ClCompile> + <ClCompile Include="..\..\..\source\modules\asura-core\image\image_data.cpp"> + <Filter>image</Filter> + </ClCompile> + <ClCompile Include="..\..\..\source\modules\asura-core\image\image_decode_task.cpp"> + <Filter>image</Filter> + </ClCompile> + <ClCompile Include="..\..\..\source\modules\asura-core\image\png_decoder.cpp"> + <Filter>image</Filter> + </ClCompile> + <ClCompile Include="..\..\..\source\modules\asura-core\image\stb_decoder.cpp"> + <Filter>image</Filter> + </ClCompile> + <ClCompile Include="..\..\..\source\modules\asura-core\mesh\mesh2d_data.cpp"> + <Filter>mesh</Filter> + </ClCompile> + <ClCompile Include="..\..\..\source\modules\asura-core\window\window.cpp"> + <Filter>window</Filter> + </ClCompile> + <ClCompile Include="..\..\..\source\modules\asura-core\window\window_impl_glew.cpp"> + <Filter>window</Filter> + </ClCompile> + <ClCompile Include="..\..\..\source\modules\asura-core\window\window_impl_glut.cpp"> + <Filter>window</Filter> + </ClCompile> + <ClCompile Include="..\..\..\source\modules\asura-core\window\window_impl_sdl.cpp"> + <Filter>window</Filter> + </ClCompile> + <ClCompile Include="..\..\..\source\modules\asura-core\window\binding\_window.cpp"> + <Filter>window\binding</Filter> + </ClCompile> + <ClCompile Include="..\..\..\source\modules\asura-core\image\binding\_image_data.cpp"> + <Filter>image\binding</Filter> + </ClCompile> + <ClCompile Include="..\..\..\source\modules\asura-core\image\binding\_image_decode_task.cpp"> + <Filter>image\binding</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\..\..\source\modules\asura-core\application.h" /> @@ -197,12 +206,6 @@ <ClInclude Include="..\..\..\source\modules\asura-core\graphics\mesh2d.h"> <Filter>graphics</Filter> </ClInclude> - <ClInclude Include="..\..\..\source\modules\asura-core\graphics\mesh2d_data.h"> - <Filter>graphics</Filter> - </ClInclude> - <ClInclude Include="..\..\..\source\modules\asura-core\graphics\png_decoder.h"> - <Filter>graphics</Filter> - </ClInclude> <ClInclude Include="..\..\..\source\modules\asura-core\graphics\quad.h"> <Filter>graphics</Filter> </ClInclude> @@ -221,9 +224,6 @@ <ClInclude Include="..\..\..\source\modules\asura-core\graphics\sprite_batch.h"> <Filter>graphics</Filter> </ClInclude> - <ClInclude Include="..\..\..\source\modules\asura-core\graphics\stb_decoder.h"> - <Filter>graphics</Filter> - </ClInclude> <ClInclude Include="..\..\..\source\modules\asura-core\graphics\texture.h"> <Filter>graphics</Filter> </ClInclude> @@ -260,27 +260,6 @@ <ClInclude Include="..\..\..\source\modules\asura-core\graphics\image.h"> <Filter>graphics</Filter> </ClInclude> - <ClInclude Include="..\..\..\source\modules\asura-core\graphics\image_data.h"> - <Filter>graphics</Filter> - </ClInclude> - <ClInclude Include="..\..\..\source\modules\asura-core\graphics\image_decode_task.h"> - <Filter>graphics</Filter> - </ClInclude> - <ClInclude Include="..\..\..\source\modules\asura-core\graphics\image_decoder.h"> - <Filter>graphics</Filter> - </ClInclude> - <ClInclude Include="..\..\..\source\modules\asura-core\wnd\window.h"> - <Filter>wnd</Filter> - </ClInclude> - <ClInclude Include="..\..\..\source\modules\asura-core\wnd\window_impl_glew.h"> - <Filter>wnd</Filter> - </ClInclude> - <ClInclude Include="..\..\..\source\modules\asura-core\wnd\window_impl_glut.h"> - <Filter>wnd</Filter> - </ClInclude> - <ClInclude Include="..\..\..\source\modules\asura-core\wnd\window_impl_sdl.h"> - <Filter>wnd</Filter> - </ClInclude> <ClInclude Include="..\..\..\source\modules\asura-core\input\clipboard.h"> <Filter>input</Filter> </ClInclude> @@ -320,6 +299,36 @@ <ClInclude Include="..\..\..\source\modules\asura-core\graphics\shader_source.h"> <Filter>graphics</Filter> </ClInclude> + <ClInclude Include="..\..\..\source\modules\asura-core\image\image_decoder.h"> + <Filter>image</Filter> + </ClInclude> + <ClInclude Include="..\..\..\source\modules\asura-core\image\image_data.h"> + <Filter>image</Filter> + </ClInclude> + <ClInclude Include="..\..\..\source\modules\asura-core\image\image_decode_task.h"> + <Filter>image</Filter> + </ClInclude> + <ClInclude Include="..\..\..\source\modules\asura-core\image\png_decoder.h"> + <Filter>image</Filter> + </ClInclude> + <ClInclude Include="..\..\..\source\modules\asura-core\image\stb_decoder.h"> + <Filter>image</Filter> + </ClInclude> + <ClInclude Include="..\..\..\source\modules\asura-core\mesh\mesh2d_data.h"> + <Filter>mesh</Filter> + </ClInclude> + <ClInclude Include="..\..\..\source\modules\asura-core\window\window.h"> + <Filter>window</Filter> + </ClInclude> + <ClInclude Include="..\..\..\source\modules\asura-core\window\window_impl_glew.h"> + <Filter>window</Filter> + </ClInclude> + <ClInclude Include="..\..\..\source\modules\asura-core\window\window_impl_glut.h"> + <Filter>window</Filter> + </ClInclude> + <ClInclude Include="..\..\..\source\modules\asura-core\window\window_impl_sdl.h"> + <Filter>window</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <None Include="..\..\..\source\modules\asura-core\font\string.inl"> diff --git a/build/modules/asura-utils/asura-utils.vcxproj b/build/modules/asura-utils/asura-utils.vcxproj index 98f526f..442e223 100644 --- a/build/modules/asura-utils/asura-utils.vcxproj +++ b/build/modules/asura-utils/asura-utils.vcxproj @@ -155,7 +155,6 @@ <ClCompile Include="..\..\..\source\modules\asura-utils\threading\thread_impl_std.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-utils\threading\thread_impl_win32.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-utils\threading\task.cpp" /> - <ClCompile Include="..\..\..\source\modules\asura-utils\threading\thread_task.cpp" /> <ClCompile Include="..\..\..\source\modules\asura-utils\utils_module.cpp" /> </ItemGroup> <ItemGroup> @@ -195,7 +194,6 @@ <ClInclude Include="..\..\..\source\modules\asura-utils\threading\thread_impl_std.h" /> <ClInclude Include="..\..\..\source\modules\asura-utils\threading\thread_impl_win32.h" /> <ClInclude Include="..\..\..\source\modules\asura-utils\threading\task.h" /> - <ClInclude Include="..\..\..\source\modules\asura-utils\threading\thread_task.h" /> <ClInclude Include="..\..\..\source\modules\asura-utils\type.h" /> <ClInclude Include="..\..\..\source\modules\asura-utils\utils.h" /> <ClInclude Include="..\..\..\source\modules\asura-utils\utils_config.h" /> diff --git a/build/modules/asura-utils/asura-utils.vcxproj.filters b/build/modules/asura-utils/asura-utils.vcxproj.filters index 967881d..3c6d092 100644 --- a/build/modules/asura-utils/asura-utils.vcxproj.filters +++ b/build/modules/asura-utils/asura-utils.vcxproj.filters @@ -113,9 +113,6 @@ <ClCompile Include="..\..\..\source\modules\asura-utils\threading\task.cpp"> <Filter>threading</Filter> </ClCompile> - <ClCompile Include="..\..\..\source\modules\asura-utils\threading\thread_task.cpp"> - <Filter>io</Filter> - </ClCompile> <ClCompile Include="..\..\..\source\modules\asura-utils\threading\semaphore.cpp"> <Filter>threading</Filter> </ClCompile> @@ -177,9 +174,6 @@ <ClInclude Include="..\..\..\source\modules\asura-utils\io\file_system.h"> <Filter>io</Filter> </ClInclude> - <ClInclude Include="..\..\..\source\modules\asura-utils\io\reloadable.h"> - <Filter>io</Filter> - </ClInclude> <ClInclude Include="..\..\..\source\modules\asura-utils\io\file_data.h"> <Filter>io</Filter> </ClInclude> @@ -219,9 +213,6 @@ <ClInclude Include="..\..\..\source\modules\asura-utils\threading\task.h"> <Filter>threading</Filter> </ClInclude> - <ClInclude Include="..\..\..\source\modules\asura-utils\threading\thread_task.h"> - <Filter>io</Filter> - </ClInclude> <ClInclude Include="..\..\..\source\modules\asura-utils\threading\semaphore.h"> <Filter>threading</Filter> </ClInclude> @@ -234,6 +225,7 @@ <ClInclude Include="..\..\..\source\modules\asura-utils\threading\conditional.h"> <Filter>threading</Filter> </ClInclude> + <ClInclude Include="..\..\..\source\modules\asura-utils\io\renewable.h" /> </ItemGroup> <ItemGroup> <None Include="..\..\..\source\modules\asura-utils\math\rect.inl"> diff --git a/build/tests/win32/01-window/01-window.vcxproj b/build/tests/win32/01-window/01-window.vcxproj index 53d9add..183d9c7 100644 --- a/build/tests/win32/01-window/01-window.vcxproj +++ b/build/tests/win32/01-window/01-window.vcxproj @@ -26,6 +26,11 @@ <ItemGroup> <ClInclude Include="..\..\..\..\source\tests\win32\01-window\config.h" /> </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\..\modules\asura-core\asura-core.vcxproj"> + <Project>{29a6837a-67fa-403f-83fd-e7975649404f}</Project> + </ProjectReference> + </ItemGroup> <PropertyGroup Label="Globals"> <VCProjectVersion>15.0</VCProjectVersion> <ProjectGuid>{B8FF8AE1-D0C1-4C7D-9FEE-5727ECE604BA}</ProjectGuid> @@ -77,13 +82,19 @@ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> </ImportGroup> <PropertyGroup Label="UserMacros" /> - <PropertyGroup /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <OutDir>$(SolutionDir)..\Bin\win64</OutDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <OutDir>$(SolutionDir)..\Bin\win64</OutDir> + </PropertyGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ClCompile> <WarningLevel>Level3</WarningLevel> <Optimization>Disabled</Optimization> <SDLCheck>true</SDLCheck> <ConformanceMode>true</ConformanceMode> + <AdditionalIncludeDirectories>$(SolutionDir)..\source\3rd-party;$(SolutionDir)..\source\modules;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> </ClCompile> <Link> <AdditionalDependencies>opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies> @@ -97,6 +108,10 @@ <SDLCheck>true</SDLCheck> <ConformanceMode>true</ConformanceMode> </ClCompile> + <Link> + <AdditionalDependencies>opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies> + <SubSystem>Windows</SubSystem> + </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ClCompile> @@ -110,6 +125,8 @@ <Link> <EnableCOMDATFolding>true</EnableCOMDATFolding> <OptimizeReferences>true</OptimizeReferences> + <AdditionalDependencies>opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies> + <SubSystem>Windows</SubSystem> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> @@ -120,6 +137,7 @@ <IntrinsicFunctions>true</IntrinsicFunctions> <SDLCheck>true</SDLCheck> <ConformanceMode>true</ConformanceMode> + <AdditionalIncludeDirectories>$(SolutionDir)..\source\3rd-party;$(SolutionDir)..\source\modules;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> </ClCompile> <Link> <EnableCOMDATFolding>true</EnableCOMDATFolding> diff --git a/build/tests/win32/01-window/01-window.vcxproj.user b/build/tests/win32/01-window/01-window.vcxproj.user index be25078..0858e0c 100644 --- a/build/tests/win32/01-window/01-window.vcxproj.user +++ b/build/tests/win32/01-window/01-window.vcxproj.user @@ -1,4 +1,11 @@ <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <PropertyGroup /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <LocalDebuggerWorkingDirectory>$(SolutionDir)..\Bin\win64</LocalDebuggerWorkingDirectory> + <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LocalDebuggerWorkingDirectory>$(SolutionDir)..\Bin\win64</LocalDebuggerWorkingDirectory> + <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> + </PropertyGroup> </Project>
\ No newline at end of file diff --git a/build/x64/Debug/01-window.exe b/build/x64/Debug/01-window.exe Binary files differdeleted file mode 100644 index 186069a..0000000 --- a/build/x64/Debug/01-window.exe +++ /dev/null diff --git a/source/3rd-party/Luax/luax_class.hpp b/source/3rd-party/Luax/luax_class.hpp index dd9414a..ba8d16a 100644 --- a/source/3rd-party/Luax/luax_class.hpp +++ b/source/3rd-party/Luax/luax_class.hpp @@ -165,7 +165,7 @@ namespace Luax /// ȡַҪַֻͨڶϴʵõջϺ;̬ı /// ȡַ֤üȷҪãʹôݶǴݵַ /// - void* operator &(); + //void* operator &(); /// /// userdataʵstate diff --git a/Source/Asura.Editor/Scripts/compile.bat b/source/Asura.Editor/controls/menu_item.cpp index e69de29..e69de29 100644 --- a/Source/Asura.Editor/Scripts/compile.bat +++ b/source/Asura.Editor/controls/menu_item.cpp diff --git a/Source/Asura.Editor/Scripts/compile.sh b/source/Asura.Editor/controls/menu_item.h index e69de29..e69de29 100644 --- a/Source/Asura.Editor/Scripts/compile.sh +++ b/source/Asura.Editor/controls/menu_item.h diff --git a/source/Asura.Editor/controls/widget.h b/source/Asura.Editor/controls/widget.h index c934351..0e881f6 100644 --- a/source/Asura.Editor/controls/widget.h +++ b/source/Asura.Editor/controls/widget.h @@ -16,7 +16,7 @@ namespace AsuraEditor /// Asura EditorĿؼȾں¼ѯֻ¼Ӧӿڡ /// ASURA_ABSTRACT class Widget - : public virtual AEScripting::NativeAccessor + : virtual public AEScripting::NativeAccessor { public: diff --git a/source/Asura.Editor/scripts/asset_view.lua b/source/Asura.Editor/editor/asset_view.lua index e69de29..e69de29 100644 --- a/source/Asura.Editor/scripts/asset_view.lua +++ b/source/Asura.Editor/editor/asset_view.lua diff --git a/Source/Asura.Editor/scripts/compile.bat b/source/Asura.Editor/editor/compile.bat index e69de29..e69de29 100644 --- a/Source/Asura.Editor/scripts/compile.bat +++ b/source/Asura.Editor/editor/compile.bat diff --git a/Source/Asura.Editor/scripts/compile.sh b/source/Asura.Editor/editor/compile.sh index e69de29..e69de29 100644 --- a/Source/Asura.Editor/scripts/compile.sh +++ b/source/Asura.Editor/editor/compile.sh diff --git a/source/Asura.Editor/scripts/compile.bat b/source/Asura.Editor/editor/idea.txt index e69de29..e69de29 100644 --- a/source/Asura.Editor/scripts/compile.bat +++ b/source/Asura.Editor/editor/idea.txt diff --git a/Source/Asura.Editor/Scripts/main.lua b/source/Asura.Editor/editor/main.lua index 76fab7a..76fab7a 100644 --- a/Source/Asura.Editor/Scripts/main.lua +++ b/source/Asura.Editor/editor/main.lua diff --git a/Source/Asura.Editor/Scripts/scene_view.lua b/source/Asura.Editor/editor/scene_view.lua index b6097f3..b6097f3 100644 --- a/Source/Asura.Editor/Scripts/scene_view.lua +++ b/source/Asura.Editor/editor/scene_view.lua diff --git a/source/Asura.Editor/scripts/main.lua b/source/Asura.Editor/scripts/main.lua deleted file mode 100644 index 76fab7a..0000000 --- a/source/Asura.Editor/scripts/main.lua +++ /dev/null @@ -1,4 +0,0 @@ - ---༭ ---༭Asura.Editor/scriptsʵ - diff --git a/source/Asura.Editor/scripts/scene_view.lua b/source/Asura.Editor/scripts/scene_view.lua deleted file mode 100644 index b6097f3..0000000 --- a/source/Asura.Editor/scripts/scene_view.lua +++ /dev/null @@ -1,4 +0,0 @@ --- 场景窗口 -local scene = AsuraEditor.Window.New("Window/Scene View") - - diff --git a/source/libs/asura-lib-core/application.cpp b/source/libs/asura-lib-core/application.cpp new file mode 100644 index 0000000..0a1c1ef --- /dev/null +++ b/source/libs/asura-lib-core/application.cpp @@ -0,0 +1,26 @@ +#include "Sdl2/SDL.h" +#include "Exceptions/Exception.h" +#include "Scripting/Luax.hpp" +#include "Application.h" + +using namespace Luax; + +namespace AsuraEngine +{ + + Application::Application() + { + + } + + Application::~Application() + { + + } + + bool Application::InitSubModules(uint flag) + { + + } + +}
\ No newline at end of file diff --git a/source/libs/asura-lib-core/application.h b/source/libs/asura-lib-core/application.h new file mode 100644 index 0000000..9606819 --- /dev/null +++ b/source/libs/asura-lib-core/application.h @@ -0,0 +1,83 @@ +#ifndef __ASURA_ENGINE_APPLICATION_H__ +#define __ASURA_ENGINE_APPLICATION_H__ + +#include <asura-lib-utils/scripting/portable.hpp> +#include <asura-lib-utils/module.h> +#include <queue> + +#include "core_config.h" + +namespace AsuraEngine +{ + + /// + /// ģ + /// + enum SubModules + { + ASURA_MODULE_NONE = 0X00000000U, + + ASURA_MODULE_GRAPHICS = 1 << 1, + ASURA_MODULE_AUDIO = 1 << 2, + ASURA_MODULE_FONT = 1 << 3, + ASURA_MODULE_INPUT = 1 << 4, + ASURA_MODULE_MATH = 1 << 5, + ASURA_MODULE_PHYSICS = 1 << 6, + ASURA_MODULE_TIME = 1 << 7, + ASURA_MODULE_WINDOW = 1 << 8, + + ASURA_MODULE_ALL = 0XFFFFFFFFU + }; + + /// + /// ѭ + /// + ASURA_ABSTRACT class Application + { + public: + + Application(); + + virtual ~Application(); + + /// + /// ʼǰϵͳ + /// + bool InitSubModules(uint flag = ASURA_MODULE_ALL); + + /// + /// + /// + virtual void Run(int argc, char* args[]); + + /// + /// ˳runʱĴ + /// + virtual void OnExit(); + + protected: + + /// + /// moduleapplicationӵmoduleȨ + /// + void EnqueueModule(Module* module); + + private: + + /// + /// ̵߳lua state handleӦѭСһ˵ֻҪ߳һlua_State̲߳Ҫ̼߳ + /// lua̫ʹˡC++дȻעһصһ̴߳lua_Stateעắִк + /// ̵߳lua_Stateֻ֤һnativeʵ֮һlua_State + /// + lua_State* mMainLuaState; + + /// + /// Asura libsᰴն˳ʼ˳ʱִ˳ + /// + std::queue<Module*> mModules; + + }; + +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/core_config.h b/source/libs/asura-lib-core/core_config.h new file mode 100644 index 0000000..06eecc7 --- /dev/null +++ b/source/libs/asura-lib-core/core_config.h @@ -0,0 +1,8 @@ +#ifndef __ASURA_CORE_CONFIG_H__ +#define __ASURA_CORE_CONFIG_H__ + +#define ASURA_CORE_SDL 1 +#define ASURA_CORE_GLUT 0 +#define ASURA_CORE_GLFW 0 + +#endif
\ No newline at end of file diff --git a/source/Asura.Editor/scripts/compile.sh b/source/libs/asura-lib-core/core_module.cpp index e69de29..e69de29 100644 --- a/source/Asura.Editor/scripts/compile.sh +++ b/source/libs/asura-lib-core/core_module.cpp diff --git a/source/libs/asura-lib-core/core_module.h b/source/libs/asura-lib-core/core_module.h new file mode 100644 index 0000000..2cded93 --- /dev/null +++ b/source/libs/asura-lib-core/core_module.h @@ -0,0 +1,11 @@ +#ifndef __ASURA_CORE_MODULE_H__ +#define __ASURA_CORE_MODULE_H__ + +namespace AsuraEngine +{ + + + +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/image_decode_task.cpp b/source/libs/asura-lib-core/font/glyph.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-core/graphics/image_decode_task.cpp +++ b/source/libs/asura-lib-core/font/glyph.cpp diff --git a/source/modules/asura-core/graphics/mesh2d_data.cpp b/source/libs/asura-lib-core/font/glyph.h index e69de29..e69de29 100644 --- a/source/modules/asura-core/graphics/mesh2d_data.cpp +++ b/source/libs/asura-lib-core/font/glyph.h diff --git a/source/libs/asura-lib-core/font/string.cpp b/source/libs/asura-lib-core/font/string.cpp new file mode 100644 index 0000000..8c9c55a --- /dev/null +++ b/source/libs/asura-lib-core/font/string.cpp @@ -0,0 +1,376 @@ +#include "String.hpp" +#include "Utf.hpp" + +namespace AsuraEngine +{ + namespace Text + { + + + //////////////////////////////////////////////////////////// + const std::size_t String::InvalidPos = std::basic_string<uint32>::npos; + + + //////////////////////////////////////////////////////////// + String::String() + { + } + + + //////////////////////////////////////////////////////////// + String::String(char ansiChar, const std::locale& locale) + { + mString += Utf32::DecodeAnsi(ansiChar, locale); + } + + + //////////////////////////////////////////////////////////// + String::String(wchar_t wideChar) + { + mString += Utf32::DecodeWide(wideChar); + } + + + //////////////////////////////////////////////////////////// + String::String(uint32 utf32Char) + { + mString += utf32Char; + } + + + //////////////////////////////////////////////////////////// + String::String(const char* ansiString, const std::locale& locale) + { + if (ansiString) + { + std::size_t length = strlen(ansiString); + if (length > 0) + { + mString.reserve(length + 1); + Utf32::FromAnsi(ansiString, ansiString + length, std::back_inserter(mString), locale); + } + } + } + + + //////////////////////////////////////////////////////////// + String::String(const std::string& ansiString, const std::locale& locale) + { + mString.reserve(ansiString.length() + 1); + Utf32::FromAnsi(ansiString.begin(), ansiString.end(), std::back_inserter(mString), locale); + } + + + //////////////////////////////////////////////////////////// + String::String(const wchar_t* wideString) + { + if (wideString) + { + std::size_t length = std::wcslen(wideString); + if (length > 0) + { + mString.reserve(length + 1); + Utf32::FromWide(wideString, wideString + length, std::back_inserter(mString)); + } + } + } + + + //////////////////////////////////////////////////////////// + String::String(const std::wstring& wideString) + { + mString.reserve(wideString.length() + 1); + Utf32::FromWide(wideString.begin(), wideString.end(), std::back_inserter(mString)); + } + + + //////////////////////////////////////////////////////////// + String::String(const uint32* utf32String) + { + if (utf32String) + mString = utf32String; + } + + + //////////////////////////////////////////////////////////// + String::String(const std::basic_string<uint32>& utf32String) : + mString(utf32String) + { + } + + + //////////////////////////////////////////////////////////// + String::String(const String& copy) : + mString(copy.mString) + { + } + + + //////////////////////////////////////////////////////////// + String::operator std::string() const + { + return ToAnsiString(); + } + + + //////////////////////////////////////////////////////////// + String::operator std::wstring() const + { + return ToWideString(); + } + + + //////////////////////////////////////////////////////////// + std::string String::ToAnsiString(const std::locale& locale) const + { + // Prepare the output string + std::string output; + output.reserve(mString.length() + 1); + + // Convert + Utf32::ToAnsi(mString.begin(), mString.end(), std::back_inserter(output), 0, locale); + + return output; + } + + + //////////////////////////////////////////////////////////// + std::wstring String::ToWideString() const + { + // Prepare the output string + std::wstring output; + output.reserve(mString.length() + 1); + + // Convert + Utf32::ToWide(mString.begin(), mString.end(), std::back_inserter(output), 0); + + return output; + } + + + //////////////////////////////////////////////////////////// + std::basic_string<uint8> String::ToUtf8() const + { + // Prepare the output string + std::basic_string<uint8> output; + output.reserve(mString.length()); + + // Convert + Utf32::ToUtf8(mString.begin(), mString.end(), std::back_inserter(output)); + + return output; + } + + + //////////////////////////////////////////////////////////// + std::basic_string<uint16> String::ToUtf16() const + { + // Prepare the output string + std::basic_string<uint16> output; + output.reserve(mString.length()); + + // Convert + Utf32::ToUtf16(mString.begin(), mString.end(), std::back_inserter(output)); + + return output; + } + + + //////////////////////////////////////////////////////////// + std::basic_string<uint32> String::ToUtf32() const + { + return mString; + } + + + //////////////////////////////////////////////////////////// + String& String::operator =(const String& right) + { + mString = right.mString; + return *this; + } + + + //////////////////////////////////////////////////////////// + String& String::operator +=(const String& right) + { + mString += right.mString; + return *this; + } + + + //////////////////////////////////////////////////////////// + uint32 String::operator [](std::size_t index) const + { + return mString[index]; + } + + + //////////////////////////////////////////////////////////// + uint32& String::operator [](std::size_t index) + { + return mString[index]; + } + + + //////////////////////////////////////////////////////////// + void String::Clear() + { + mString.clear(); + } + + + //////////////////////////////////////////////////////////// + std::size_t String::GetSize() const + { + return mString.size(); + } + + + //////////////////////////////////////////////////////////// + bool String::IsEmpty() const + { + return mString.empty(); + } + + + //////////////////////////////////////////////////////////// + void String::Erase(std::size_t position, std::size_t count) + { + mString.erase(position, count); + } + + + //////////////////////////////////////////////////////////// + void String::Insert(std::size_t position, const String& str) + { + mString.insert(position, str.mString); + } + + + //////////////////////////////////////////////////////////// + std::size_t String::Find(const String& str, std::size_t start) const + { + return mString.find(str.mString, start); + } + + + //////////////////////////////////////////////////////////// + void String::Replace(std::size_t position, std::size_t length, const String& replaceWith) + { + mString.replace(position, length, replaceWith.mString); + } + + + //////////////////////////////////////////////////////////// + void String::Replace(const String& searchFor, const String& replaceWith) + { + std::size_t step = replaceWith.GetSize(); + std::size_t len = searchFor.GetSize(); + std::size_t pos = Find(searchFor); + + // Replace each occurrence of search + while (pos != InvalidPos) + { + Replace(pos, len, replaceWith); + pos = Find(searchFor, pos + step); + } + } + + + //////////////////////////////////////////////////////////// + String String::Substring(std::size_t position, std::size_t length) const + { + return mString.substr(position, length); + } + + + //////////////////////////////////////////////////////////// + const uint32* String::GetData() const + { + return mString.c_str(); + } + + + //////////////////////////////////////////////////////////// + String::Iterator String::Begin() + { + return mString.begin(); + } + + + //////////////////////////////////////////////////////////// + String::ConstIterator String::Begin() const + { + return mString.begin(); + } + + + //////////////////////////////////////////////////////////// + String::Iterator String::End() + { + return mString.end(); + } + + + //////////////////////////////////////////////////////////// + String::ConstIterator String::End() const + { + return mString.end(); + } + + + //////////////////////////////////////////////////////////// + bool operator ==(const String& left, const String& right) + { + return left.mString == right.mString; + } + + + //////////////////////////////////////////////////////////// + bool operator !=(const String& left, const String& right) + { + return !(left == right); + } + + + //////////////////////////////////////////////////////////// + bool operator <(const String& left, const String& right) + { + return left.mString < right.mString; + } + + + //////////////////////////////////////////////////////////// + bool operator >(const String& left, const String& right) + { + return right < left; + } + + + //////////////////////////////////////////////////////////// + bool operator <=(const String& left, const String& right) + { + return !(right < left); + } + + + //////////////////////////////////////////////////////////// + bool operator >=(const String& left, const String& right) + { + return !(left < right); + } + + + //////////////////////////////////////////////////////////// + String operator +(const String& left, const String& right) + { + String string = left; + string += right; + + return string; + } + + + } +} diff --git a/source/libs/asura-lib-core/font/string.hpp b/source/libs/asura-lib-core/font/string.hpp new file mode 100644 index 0000000..226735b --- /dev/null +++ b/source/libs/asura-lib-core/font/string.hpp @@ -0,0 +1,594 @@ +#ifndef __ASURA_ENGINE_STRING_H__ +#define __ASURA_ENGINE_STRING_H__ + +#include "Config.h" +#include <iterator> +#include <locale> +#include <string> + +namespace AsuraEngine +{ + namespace Text + { + + + //////////////////////////////////////////////////////////// + /// \brief Utility string class that automatically handles + /// conversions between types and encodings + /// + //////////////////////////////////////////////////////////// + class String + { + public: + + //////////////////////////////////////////////////////////// + // Types + //////////////////////////////////////////////////////////// + typedef std::basic_string<uint32>::iterator Iterator; ///< Iterator type + typedef std::basic_string<uint32>::const_iterator ConstIterator; ///< Read-only iterator type + + //////////////////////////////////////////////////////////// + // Static member data + //////////////////////////////////////////////////////////// + static const std::size_t InvalidPos; ///< Represents an invalid position in the string + + //////////////////////////////////////////////////////////// + /// \brief Default constructor + /// + /// This constructor creates an empty string. + /// + //////////////////////////////////////////////////////////// + String(); + + //////////////////////////////////////////////////////////// + /// \brief Construct from a single ANSI character and a locale + /// + /// The source character is converted to UTF-32 according + /// to the given locale. + /// + /// \param ansiChar ANSI character to convert + /// \param locale Locale to use for conversion + /// + //////////////////////////////////////////////////////////// + String(char ansiChar, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Construct from single wide character + /// + /// \param wideChar Wide character to convert + /// + //////////////////////////////////////////////////////////// + String(wchar_t wideChar); + + //////////////////////////////////////////////////////////// + /// \brief Construct from single UTF-32 character + /// + /// \param utf32Char UTF-32 character to convert + /// + //////////////////////////////////////////////////////////// + String(uint utf32Char); + + //////////////////////////////////////////////////////////// + /// \brief Construct from a null-terminated C-style ANSI string and a locale + /// + /// The source string is converted to UTF-32 according + /// to the given locale. + /// + /// \param ansiString ANSI string to convert + /// \param locale Locale to use for conversion + /// + //////////////////////////////////////////////////////////// + String(const char* ansiString, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Construct from an ANSI string and a locale + /// + /// The source string is converted to UTF-32 according + /// to the given locale. + /// + /// \param ansiString ANSI string to convert + /// \param locale Locale to use for conversion + /// + //////////////////////////////////////////////////////////// + String(const std::string& ansiString, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Construct from null-terminated C-style wide string + /// + /// \param wideString Wide string to convert + /// + //////////////////////////////////////////////////////////// + String(const wchar_t* wideString); + + //////////////////////////////////////////////////////////// + /// \brief Construct from a wide string + /// + /// \param wideString Wide string to convert + /// + //////////////////////////////////////////////////////////// + String(const std::wstring& wideString); + + //////////////////////////////////////////////////////////// + /// \brief Construct from a null-terminated C-style UTF-32 string + /// + /// \param utf32String UTF-32 string to assign + /// + //////////////////////////////////////////////////////////// + String(const uint* utf32String); + + //////////////////////////////////////////////////////////// + /// \brief Construct from an UTF-32 string + /// + /// \param utf32String UTF-32 string to assign + /// + //////////////////////////////////////////////////////////// + String(const std::basic_string<uint>& utf32String); + + //////////////////////////////////////////////////////////// + /// \brief Copy constructor + /// + /// \param copy Instance to copy + /// + //////////////////////////////////////////////////////////// + String(const String& copy); + + //////////////////////////////////////////////////////////// + /// \brief Create a new sf::String from a UTF-8 encoded string + /// + /// \param begin Forward iterator to the beginning of the UTF-8 sequence + /// \param end Forward iterator to the end of the UTF-8 sequence + /// + /// \return A sf::String containing the source string + /// + /// \see fromUtf16, fromUtf32 + /// + //////////////////////////////////////////////////////////// + template <typename T> + static String FromUtf8(T begin, T end); + + //////////////////////////////////////////////////////////// + /// \brief Create a new sf::String from a UTF-16 encoded string + /// + /// \param begin Forward iterator to the beginning of the UTF-16 sequence + /// \param end Forward iterator to the end of the UTF-16 sequence + /// + /// \return A sf::String containing the source string + /// + /// \see fromUtf8, fromUtf32 + /// + //////////////////////////////////////////////////////////// + template <typename T> + static String FromUtf16(T begin, T end); + + //////////////////////////////////////////////////////////// + /// \brief Create a new sf::String from a UTF-32 encoded string + /// + /// This function is provided for consistency, it is equivalent to + /// using the constructors that takes a const sf::uint* or + /// a std::basic_string<sf::uint>. + /// + /// \param begin Forward iterator to the beginning of the UTF-32 sequence + /// \param end Forward iterator to the end of the UTF-32 sequence + /// + /// \return A sf::String containing the source string + /// + /// \see fromUtf8, fromUtf16 + /// + //////////////////////////////////////////////////////////// + template <typename T> + static String FromUtf32(T begin, T end); + + //////////////////////////////////////////////////////////// + /// \brief Implicit conversion operator to std::string (ANSI string) + /// + /// The current global locale is used for conversion. If you + /// want to explicitly specify a locale, see toAnsiString. + /// Characters that do not fit in the target encoding are + /// discarded from the returned string. + /// This operator is defined for convenience, and is equivalent + /// to calling toAnsiString(). + /// + /// \return Converted ANSI string + /// + /// \see toAnsiString, operator std::wstring + /// + //////////////////////////////////////////////////////////// + operator std::string() const; + + //////////////////////////////////////////////////////////// + /// \brief Implicit conversion operator to std::wstring (wide string) + /// + /// Characters that do not fit in the target encoding are + /// discarded from the returned string. + /// This operator is defined for convenience, and is equivalent + /// to calling toWideString(). + /// + /// \return Converted wide string + /// + /// \see toWideString, operator std::string + /// + //////////////////////////////////////////////////////////// + operator std::wstring() const; + + //////////////////////////////////////////////////////////// + /// \brief Convert the Unicode string to an ANSI string + /// + /// The UTF-32 string is converted to an ANSI string in + /// the encoding defined by \a locale. + /// Characters that do not fit in the target encoding are + /// discarded from the returned string. + /// + /// \param locale Locale to use for conversion + /// + /// \return Converted ANSI string + /// + /// \see toWideString, operator std::string + /// + //////////////////////////////////////////////////////////// + std::string ToAnsiString(const std::locale& locale = std::locale()) const; + + //////////////////////////////////////////////////////////// + /// \brief Convert the Unicode string to a wide string + /// + /// Characters that do not fit in the target encoding are + /// discarded from the returned string. + /// + /// \return Converted wide string + /// + /// \see toAnsiString, operator std::wstring + /// + //////////////////////////////////////////////////////////// + std::wstring ToWideString() const; + + //////////////////////////////////////////////////////////// + /// \brief Convert the Unicode string to a UTF-8 string + /// + /// \return Converted UTF-8 string + /// + /// \see toUtf16, toUtf32 + /// + //////////////////////////////////////////////////////////// + std::basic_string<uint8> ToUtf8() const; + + //////////////////////////////////////////////////////////// + /// \brief Convert the Unicode string to a UTF-16 string + /// + /// \return Converted UTF-16 string + /// + /// \see toUtf8, toUtf32 + /// + //////////////////////////////////////////////////////////// + std::basic_string<uint16> ToUtf16() const; + + //////////////////////////////////////////////////////////// + /// \brief Convert the Unicode string to a UTF-32 string + /// + /// This function doesn't perform any conversion, since the + /// string is already stored as UTF-32 internally. + /// + /// \return Converted UTF-32 string + /// + /// \see toUtf8, toUtf16 + /// + //////////////////////////////////////////////////////////// + std::basic_string<uint> ToUtf32() const; + + //////////////////////////////////////////////////////////// + /// \brief Overload of assignment operator + /// + /// \param right Instance to assign + /// + /// \return Reference to self + /// + //////////////////////////////////////////////////////////// + String& operator =(const String& right); + + //////////////////////////////////////////////////////////// + /// \brief Overload of += operator to append an UTF-32 string + /// + /// \param right String to append + /// + /// \return Reference to self + /// + //////////////////////////////////////////////////////////// + String& operator +=(const String& right); + + //////////////////////////////////////////////////////////// + /// \brief Overload of [] operator to access a character by its position + /// + /// This function provides read-only access to characters. + /// Note: the behavior is undefined if \a index is out of range. + /// + /// \param index Index of the character to get + /// + /// \return Character at position \a index + /// + //////////////////////////////////////////////////////////// + uint operator [](std::size_t index) const; + + //////////////////////////////////////////////////////////// + /// \brief Overload of [] operator to access a character by its position + /// + /// This function provides read and write access to characters. + /// Note: the behavior is undefined if \a index is out of range. + /// + /// \param index Index of the character to get + /// + /// \return Reference to the character at position \a index + /// + //////////////////////////////////////////////////////////// + uint& operator [](std::size_t index); + + //////////////////////////////////////////////////////////// + /// \brief Clear the string + /// + /// This function removes all the characters from the string. + /// + /// \see isEmpty, erase + /// + //////////////////////////////////////////////////////////// + void Clear(); + + //////////////////////////////////////////////////////////// + /// \brief Get the size of the string + /// + /// \return Number of characters in the string + /// + /// \see isEmpty + /// + //////////////////////////////////////////////////////////// + std::size_t GetSize() const; + + //////////////////////////////////////////////////////////// + /// \brief Check whether the string is empty or not + /// + /// \return True if the string is empty (i.e. contains no character) + /// + /// \see clear, getSize + /// + //////////////////////////////////////////////////////////// + bool IsEmpty() const; + + //////////////////////////////////////////////////////////// + /// \brief Erase one or more characters from the string + /// + /// This function removes a sequence of \a count characters + /// starting from \a position. + /// + /// \param position Position of the first character to erase + /// \param count Number of characters to erase + /// + //////////////////////////////////////////////////////////// + void Erase(std::size_t position, std::size_t count = 1); + + //////////////////////////////////////////////////////////// + /// \brief Insert one or more characters into the string + /// + /// This function inserts the characters of \a str + /// into the string, starting from \a position. + /// + /// \param position Position of insertion + /// \param str Characters to insert + /// + //////////////////////////////////////////////////////////// + void Insert(std::size_t position, const String& str); + + //////////////////////////////////////////////////////////// + /// \brief Find a sequence of one or more characters in the string + /// + /// This function searches for the characters of \a str + /// in the string, starting from \a start. + /// + /// \param str Characters to find + /// \param start Where to begin searching + /// + /// \return Position of \a str in the string, or String::InvalidPos if not found + /// + //////////////////////////////////////////////////////////// + std::size_t Find(const String& str, std::size_t start = 0) const; + + //////////////////////////////////////////////////////////// + /// \brief Replace a substring with another string + /// + /// This function replaces the substring that starts at index \a position + /// and spans \a length characters with the string \a replaceWith. + /// + /// \param position Index of the first character to be replaced + /// \param length Number of characters to replace. You can pass InvalidPos to + /// replace all characters until the end of the string. + /// \param replaceWith String that replaces the given substring. + /// + //////////////////////////////////////////////////////////// + void Replace(std::size_t position, std::size_t length, const String& replaceWith); + + //////////////////////////////////////////////////////////// + /// \brief Replace all occurrences of a substring with a replacement string + /// + /// This function replaces all occurrences of \a searchFor in this string + /// with the string \a replaceWith. + /// + /// \param searchFor The value being searched for + /// \param replaceWith The value that replaces found \a searchFor values + /// + //////////////////////////////////////////////////////////// + void Replace(const String& searchFor, const String& replaceWith); + + //////////////////////////////////////////////////////////// + /// \brief Return a part of the string + /// + /// This function returns the substring that starts at index \a position + /// and spans \a length characters. + /// + /// \param position Index of the first character + /// \param length Number of characters to include in the substring (if + /// the string is shorter, as many characters as possible + /// are included). \ref InvalidPos can be used to include all + /// characters until the end of the string. + /// + /// \return String object containing a substring of this object + /// + //////////////////////////////////////////////////////////// + String Substring(std::size_t position, std::size_t length = InvalidPos) const; + + //////////////////////////////////////////////////////////// + /// \brief Get a pointer to the C-style array of characters + /// + /// This functions provides a read-only access to a + /// null-terminated C-style representation of the string. + /// The returned pointer is temporary and is meant only for + /// immediate use, thus it is not recommended to store it. + /// + /// \return Read-only pointer to the array of characters + /// + //////////////////////////////////////////////////////////// + const uint* GetData() const; + + //////////////////////////////////////////////////////////// + /// \brief Return an iterator to the beginning of the string + /// + /// \return Read-write iterator to the beginning of the string characters + /// + /// \see end + /// + //////////////////////////////////////////////////////////// + Iterator Begin(); + + //////////////////////////////////////////////////////////// + /// \brief Return an iterator to the beginning of the string + /// + /// \return Read-only iterator to the beginning of the string characters + /// + /// \see end + /// + //////////////////////////////////////////////////////////// + ConstIterator Begin() const; + + //////////////////////////////////////////////////////////// + /// \brief Return an iterator to the end of the string + /// + /// The end iterator refers to 1 position past the last character; + /// thus it represents an invalid character and should never be + /// accessed. + /// + /// \return Read-write iterator to the end of the string characters + /// + /// \see begin + /// + //////////////////////////////////////////////////////////// + Iterator End(); + + //////////////////////////////////////////////////////////// + /// \brief Return an iterator to the end of the string + /// + /// The end iterator refers to 1 position past the last character; + /// thus it represents an invalid character and should never be + /// accessed. + /// + /// \return Read-only iterator to the end of the string characters + /// + /// \see begin + /// + //////////////////////////////////////////////////////////// + ConstIterator End() const; + + private: + + friend bool operator ==(const String& left, const String& right); + friend bool operator <(const String& left, const String& right); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + std::basic_string<uint> mString; ///< Internal string of UTF-32 characters + }; + + //////////////////////////////////////////////////////////// + /// \relates String + /// \brief Overload of == operator to compare two UTF-32 strings + /// + /// \param left Left operand (a string) + /// \param right Right operand (a string) + /// + /// \return True if both strings are equal + /// + //////////////////////////////////////////////////////////// + bool operator ==(const String& left, const String& right); + + //////////////////////////////////////////////////////////// + /// \relates String + /// \brief Overload of != operator to compare two UTF-32 strings + /// + /// \param left Left operand (a string) + /// \param right Right operand (a string) + /// + /// \return True if both strings are different + /// + //////////////////////////////////////////////////////////// + bool operator !=(const String& left, const String& right); + + //////////////////////////////////////////////////////////// + /// \relates String + /// \brief Overload of < operator to compare two UTF-32 strings + /// + /// \param left Left operand (a string) + /// \param right Right operand (a string) + /// + /// \return True if \a left is lexicographically before \a right + /// + //////////////////////////////////////////////////////////// + bool operator <(const String& left, const String& right); + + //////////////////////////////////////////////////////////// + /// \relates String + /// \brief Overload of > operator to compare two UTF-32 strings + /// + /// \param left Left operand (a string) + /// \param right Right operand (a string) + /// + /// \return True if \a left is lexicographically after \a right + /// + //////////////////////////////////////////////////////////// + bool operator >(const String& left, const String& right); + + //////////////////////////////////////////////////////////// + /// \relates String + /// \brief Overload of <= operator to compare two UTF-32 strings + /// + /// \param left Left operand (a string) + /// \param right Right operand (a string) + /// + /// \return True if \a left is lexicographically before or equivalent to \a right + /// + //////////////////////////////////////////////////////////// + bool operator <=(const String& left, const String& right); + + //////////////////////////////////////////////////////////// + /// \relates String + /// \brief Overload of >= operator to compare two UTF-32 strings + /// + /// \param left Left operand (a string) + /// \param right Right operand (a string) + /// + /// \return True if \a left is lexicographically after or equivalent to \a right + /// + //////////////////////////////////////////////////////////// + bool operator >=(const String& left, const String& right); + + //////////////////////////////////////////////////////////// + /// \relates String + /// \brief Overload of binary + operator to concatenate two strings + /// + /// \param left Left operand (a string) + /// \param right Right operand (a string) + /// + /// \return Concatenated string + /// + //////////////////////////////////////////////////////////// + String operator +(const String& left, const String& right); + + #include "String.inl" + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/font/string.inl b/source/libs/asura-lib-core/font/string.inl new file mode 100644 index 0000000..ef18228 --- /dev/null +++ b/source/libs/asura-lib-core/font/string.inl @@ -0,0 +1,29 @@ + +//////////////////////////////////////////////////////////// +template <typename T> +String String::fromUtf8(T begin, T end) +{ + String string; + Utf8::toUtf32(begin, end, std::back_inserter(string.m_string)); + return string; +} + + +//////////////////////////////////////////////////////////// +template <typename T> +String String::fromUtf16(T begin, T end) +{ + String string; + Utf16::toUtf32(begin, end, std::back_inserter(string.m_string)); + return string; +} + + +//////////////////////////////////////////////////////////// +template <typename T> +String String::fromUtf32(T begin, T end) +{ + String string; + string.m_string.assign(begin, end); + return string; +} diff --git a/source/modules/asura-core/graphics/mesh2d_data.h b/source/libs/asura-lib-core/font/ttf.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-core/graphics/mesh2d_data.h +++ b/source/libs/asura-lib-core/font/ttf.cpp diff --git a/source/libs/asura-lib-core/font/ttf.h b/source/libs/asura-lib-core/font/ttf.h new file mode 100644 index 0000000..840b63e --- /dev/null +++ b/source/libs/asura-lib-core/font/ttf.h @@ -0,0 +1,17 @@ +#ifndef __ASURA_TTF_H__ +#define __ASURA_TTF_H__ + +namespace AsuraEngine +{ + namespace Text + { + + class TTF + { + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/font/utf.hpp b/source/libs/asura-lib-core/font/utf.hpp new file mode 100644 index 0000000..2e04ee4 --- /dev/null +++ b/source/libs/asura-lib-core/font/utf.hpp @@ -0,0 +1,720 @@ +#ifndef __ASURA_UTF_HPP__ +#define __ASURA_UTF_HPP__ + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include <algorithm> +#include <locale> +#include <string> +#include <cstdlib> + +namespace AsuraEngine +{ + namespace Text + { + + template <unsigned int N> + class Utf; + + //////////////////////////////////////////////////////////// + /// \brief Specialization of the Utf template for UTF-8 + /// + //////////////////////////////////////////////////////////// + template <> + class Utf<8> + { + public: + + //////////////////////////////////////////////////////////// + /// \brief Decode a single UTF-8 character + /// + /// Decoding a character means finding its unique 32-bits + /// code (called the codepoint) in the Unicode standard. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Codepoint of the decoded UTF-8 character + /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template <typename In> + static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Encode a single UTF-8 character + /// + /// Encoding a character means converting a unique 32-bits + /// code (called the codepoint) in the target encoding, UTF-8. + /// + /// \param input Codepoint to encode as UTF-8 + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to UTF-8 (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename Out> + static Out Encode(Uint32 input, Out output, Uint8 replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Advance to the next UTF-8 character + /// + /// This function is necessary for multi-elements encodings, as + /// a single character may use more than 1 storage element. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template <typename In> + static In Next(In begin, In end); + + //////////////////////////////////////////////////////////// + /// \brief Count the number of characters of a UTF-8 sequence + /// + /// This function is necessary for multi-elements encodings, as + /// a single character may use more than 1 storage element, thus the + /// total size can be different from (begin - end). + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template <typename In> + static std::size_t Count(In begin, In end); + + //////////////////////////////////////////////////////////// + /// \brief Convert an ANSI characters range to UTF-8 + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Convert a wide characters range to UTF-8 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out FromWide(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-8 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out FromLatin1(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-8 characters range to ANSI characters + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-8 characters range to wide characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-8 characters range to latin-1 (ISO-5589-1) characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToLatin1(In begin, In end, Out output, char replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-8 characters range to UTF-8 + /// + /// This functions does nothing more than a direct copy; + /// it is defined only to provide the same interface as other + /// specializations of the sf::Utf<> template, and allow + /// generic code to be written on top of it. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToUtf8(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-8 characters range to UTF-16 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToUtf16(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-8 characters range to UTF-32 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToUtf32(In begin, In end, Out output); + }; + + //////////////////////////////////////////////////////////// + /// \brief Specialization of the Utf template for UTF-16 + /// + //////////////////////////////////////////////////////////// + template <> + class Utf<16> + { + public: + + //////////////////////////////////////////////////////////// + /// \brief Decode a single UTF-16 character + /// + /// Decoding a character means finding its unique 32-bits + /// code (called the codepoint) in the Unicode standard. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Codepoint of the decoded UTF-16 character + /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template <typename In> + static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Encode a single UTF-16 character + /// + /// Encoding a character means converting a unique 32-bits + /// code (called the codepoint) in the target encoding, UTF-16. + /// + /// \param input Codepoint to encode as UTF-16 + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to UTF-16 (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename Out> + static Out Encode(Uint32 input, Out output, Uint16 replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Advance to the next UTF-16 character + /// + /// This function is necessary for multi-elements encodings, as + /// a single character may use more than 1 storage element. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template <typename In> + static In Next(In begin, In end); + + //////////////////////////////////////////////////////////// + /// \brief Count the number of characters of a UTF-16 sequence + /// + /// This function is necessary for multi-elements encodings, as + /// a single character may use more than 1 storage element, thus the + /// total size can be different from (begin - end). + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template <typename In> + static std::size_t Count(In begin, In end); + + //////////////////////////////////////////////////////////// + /// \brief Convert an ANSI characters range to UTF-16 + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Convert a wide characters range to UTF-16 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out FromWide(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-16 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out FromLatin1(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-16 characters range to ANSI characters + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-16 characters range to wide characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToLatin1(In begin, In end, Out output, char replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-16 characters range to UTF-8 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToUtf8(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-16 characters range to UTF-16 + /// + /// This functions does nothing more than a direct copy; + /// it is defined only to provide the same interface as other + /// specializations of the sf::Utf<> template, and allow + /// generic code to be written on top of it. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToUtf16(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-16 characters range to UTF-32 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToUtf32(In begin, In end, Out output); + }; + + //////////////////////////////////////////////////////////// + /// \brief Specialization of the Utf template for UTF-32 + /// + //////////////////////////////////////////////////////////// + template <> + class Utf<32> + { + public: + + //////////////////////////////////////////////////////////// + /// \brief Decode a single UTF-32 character + /// + /// Decoding a character means finding its unique 32-bits + /// code (called the codepoint) in the Unicode standard. + /// For UTF-32, the character value is the same as the codepoint. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Codepoint of the decoded UTF-32 character + /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template <typename In> + static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Encode a single UTF-32 character + /// + /// Encoding a character means converting a unique 32-bits + /// code (called the codepoint) in the target encoding, UTF-32. + /// For UTF-32, the codepoint is the same as the character value. + /// + /// \param input Codepoint to encode as UTF-32 + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to UTF-32 (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename Out> + static Out Encode(Uint32 input, Out output, Uint32 replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Advance to the next UTF-32 character + /// + /// This function is trivial for UTF-32, which can store + /// every character in a single storage element. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template <typename In> + static In Next(In begin, In end); + + //////////////////////////////////////////////////////////// + /// \brief Count the number of characters of a UTF-32 sequence + /// + /// This function is trivial for UTF-32, which can store + /// every character in a single storage element. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template <typename In> + static std::size_t Count(In begin, In end); + + //////////////////////////////////////////////////////////// + /// \brief Convert an ANSI characters range to UTF-32 + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Convert a wide characters range to UTF-32 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out FromWide(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-32 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out FromLatin1(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-32 characters range to ANSI characters + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-32 characters range to wide characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToLatin1(In begin, In end, Out output, char replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-32 characters range to UTF-8 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToUtf8(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-32 characters range to UTF-16 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToUtf16(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-32 characters range to UTF-32 + /// + /// This functions does nothing more than a direct copy; + /// it is defined only to provide the same interface as other + /// specializations of the sf::Utf<> template, and allow + /// generic code to be written on top of it. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename In, typename Out> + static Out ToUtf32(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Decode a single ANSI character to UTF-32 + /// + /// This function does not exist in other specializations + /// of sf::Utf<>, it is defined for convenience (it is used by + /// several other conversion functions). + /// + /// \param input Input ANSI character + /// \param locale Locale to use for conversion + /// + /// \return Converted character + /// + //////////////////////////////////////////////////////////// + template <typename In> + static Uint32 DecodeAnsi(In input, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Decode a single wide character to UTF-32 + /// + /// This function does not exist in other specializations + /// of sf::Utf<>, it is defined for convenience (it is used by + /// several other conversion functions). + /// + /// \param input Input wide character + /// + /// \return Converted character + /// + //////////////////////////////////////////////////////////// + template <typename In> + static Uint32 DecodeWide(In input); + + //////////////////////////////////////////////////////////// + /// \brief Encode a single UTF-32 character to ANSI + /// + /// This function does not exist in other specializations + /// of sf::Utf<>, it is defined for convenience (it is used by + /// several other conversion functions). + /// + /// \param codepoint Iterator pointing to the beginning of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement if the input character is not convertible to ANSI (use 0 to skip it) + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename Out> + static Out EncodeAnsi(Uint32 codepoint, Out output, char replacement = 0, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Encode a single UTF-32 character to wide + /// + /// This function does not exist in other specializations + /// of sf::Utf<>, it is defined for convenience (it is used by + /// several other conversion functions). + /// + /// \param codepoint Iterator pointing to the beginning of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement if the input character is not convertible to wide (use 0 to skip it) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template <typename Out> + static Out EncodeWide(Uint32 codepoint, Out output, wchar_t replacement = 0); + }; + +#include "Utf.inl" + + // Make typedefs to get rid of the template syntax + typedef Utf<8> Utf8; + typedef Utf<16> Utf16; + typedef Utf<32> Utf32; + + } // namespace sf + +} + + +#endif // SFML_UTF_HPP diff --git a/source/libs/asura-lib-core/font/utf.inl b/source/libs/asura-lib-core/font/utf.inl new file mode 100644 index 0000000..69a523b --- /dev/null +++ b/source/libs/asura-lib-core/font/utf.inl @@ -0,0 +1,752 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2019 Laurent Gomila (laurent@sfml-dev.org) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////// +// References: +// +// https://www.unicode.org/ +// https://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.c +// https://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.h +// https://people.w3.org/rishida/scripts/uniview/conversion +// +//////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////// +template <typename In> +In Utf<8>::Decode(In begin, In end, Uint32& output, Uint32 replacement) +{ + // Some useful precomputed data + static const int trailing[256] = + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 + }; + static const Uint32 offsets[6] = + { + 0x00000000, 0x00003080, 0x000E2080, 0x03C82080, 0xFA082080, 0x82082080 + }; + + // decode the character + int trailingBytes = trailing[static_cast<Uint8>(*begin)]; + if (begin + trailingBytes < end) + { + output = 0; + switch (trailingBytes) + { + case 5: output += static_cast<Uint8>(*begin++); output <<= 6; + case 4: output += static_cast<Uint8>(*begin++); output <<= 6; + case 3: output += static_cast<Uint8>(*begin++); output <<= 6; + case 2: output += static_cast<Uint8>(*begin++); output <<= 6; + case 1: output += static_cast<Uint8>(*begin++); output <<= 6; + case 0: output += static_cast<Uint8>(*begin++); + } + output -= offsets[trailingBytes]; + } + else + { + // Incomplete character + begin = end; + output = replacement; + } + + return begin; +} + + +//////////////////////////////////////////////////////////// +template <typename Out> +Out Utf<8>::Encode(Uint32 input, Out output, Uint8 replacement) +{ + // Some useful precomputed data + static const Uint8 firstBytes[7] = + { + 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC + }; + + // encode the character + if ((input > 0x0010FFFF) || ((input >= 0xD800) && (input <= 0xDBFF))) + { + // Invalid character + if (replacement) + *output++ = replacement; + } + else + { + // Valid character + + // Get the number of bytes to write + std::size_t bytestoWrite = 1; + if (input < 0x80) bytestoWrite = 1; + else if (input < 0x800) bytestoWrite = 2; + else if (input < 0x10000) bytestoWrite = 3; + else if (input <= 0x0010FFFF) bytestoWrite = 4; + + // Extract the bytes to write + Uint8 bytes[4]; + switch (bytestoWrite) + { + case 4: bytes[3] = static_cast<Uint8>((input | 0x80) & 0xBF); input >>= 6; + case 3: bytes[2] = static_cast<Uint8>((input | 0x80) & 0xBF); input >>= 6; + case 2: bytes[1] = static_cast<Uint8>((input | 0x80) & 0xBF); input >>= 6; + case 1: bytes[0] = static_cast<Uint8> (input | firstBytes[bytestoWrite]); + } + + // Add them to the output + output = std::copy(bytes, bytes + bytestoWrite, output); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In> +In Utf<8>::Next(In begin, In end) +{ + Uint32 codepoint; + return Decode(begin, end, codepoint); +} + + +//////////////////////////////////////////////////////////// +template <typename In> +std::size_t Utf<8>::Count(In begin, In end) +{ + std::size_t length = 0; + while (begin < end) + { + begin = Next(begin, end); + ++length; + } + + return length; +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<8>::FromAnsi(In begin, In end, Out output, const std::locale& locale) +{ + while (begin < end) + { + Uint32 codepoint = Utf<32>::DecodeAnsi(*begin++, locale); + output = Encode(codepoint, output); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<8>::FromWide(In begin, In end, Out output) +{ + while (begin < end) + { + Uint32 codepoint = Utf<32>::DecodeWide(*begin++); + output = Encode(codepoint, output); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<8>::FromLatin1(In begin, In end, Out output) +{ + // Latin-1 is directly compatible with Unicode encodings, + // and can thus be treated as (a sub-range of) UTF-32 + while (begin < end) + output = Encode(*begin++, output); + + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<8>::ToAnsi(In begin, In end, Out output, char replacement, const std::locale& locale) +{ + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + output = Utf<32>::EncodeAnsi(codepoint, output, replacement, locale); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<8>::ToWide(In begin, In end, Out output, wchar_t replacement) +{ + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + output = Utf<32>::EncodeWide(codepoint, output, replacement); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<8>::ToLatin1(In begin, In end, Out output, char replacement) +{ + // Latin-1 is directly compatible with Unicode encodings, + // and can thus be treated as (a sub-range of) UTF-32 + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + *output++ = codepoint < 256 ? static_cast<char>(codepoint) : replacement; + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<8>::ToUtf8(In begin, In end, Out output) +{ + return std::copy(begin, end, output); +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<8>::ToUtf16(In begin, In end, Out output) +{ + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + output = Utf<16>::Encode(codepoint, output); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<8>::ToUtf32(In begin, In end, Out output) +{ + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + *output++ = codepoint; + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In> +In Utf<16>::Decode(In begin, In end, Uint32& output, Uint32 replacement) +{ + Uint16 first = *begin++; + + // If it's a surrogate pair, first convert to a single UTF-32 character + if ((first >= 0xD800) && (first <= 0xDBFF)) + { + if (begin < end) + { + Uint32 second = *begin++; + if ((second >= 0xDC00) && (second <= 0xDFFF)) + { + // The second element is valid: convert the two elements to a UTF-32 character + output = ((first - 0xD800) << 10) + (second - 0xDC00) + 0x0010000; + } + else + { + // Invalid character + output = replacement; + } + } + else + { + // Invalid character + begin = end; + output = replacement; + } + } + else + { + // We can make a direct copy + output = first; + } + + return begin; +} + + +//////////////////////////////////////////////////////////// +template <typename Out> +Out Utf<16>::Encode(Uint32 input, Out output, Uint16 replacement) +{ + if (input <= 0xFFFF) + { + // The character can be copied directly, we just need to check if it's in the valid range + if ((input >= 0xD800) && (input <= 0xDFFF)) + { + // Invalid character (this range is reserved) + if (replacement) + *output++ = replacement; + } + else + { + // Valid character directly convertible to a single UTF-16 character + *output++ = static_cast<Uint16>(input); + } + } + else if (input > 0x0010FFFF) + { + // Invalid character (greater than the maximum Unicode value) + if (replacement) + *output++ = replacement; + } + else + { + // The input character will be converted to two UTF-16 elements + input -= 0x0010000; + *output++ = static_cast<Uint16>((input >> 10) + 0xD800); + *output++ = static_cast<Uint16>((input & 0x3FFUL) + 0xDC00); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In> +In Utf<16>::Next(In begin, In end) +{ + Uint32 codepoint; + return Decode(begin, end, codepoint); +} + + +//////////////////////////////////////////////////////////// +template <typename In> +std::size_t Utf<16>::Count(In begin, In end) +{ + std::size_t length = 0; + while (begin < end) + { + begin = Next(begin, end); + ++length; + } + + return length; +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<16>::FromAnsi(In begin, In end, Out output, const std::locale& locale) +{ + while (begin < end) + { + Uint32 codepoint = Utf<32>::DecodeAnsi(*begin++, locale); + output = Encode(codepoint, output); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<16>::FromWide(In begin, In end, Out output) +{ + while (begin < end) + { + Uint32 codepoint = Utf<32>::DecodeWide(*begin++); + output = Encode(codepoint, output); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<16>::FromLatin1(In begin, In end, Out output) +{ + // Latin-1 is directly compatible with Unicode encodings, + // and can thus be treated as (a sub-range of) UTF-32 + return std::copy(begin, end, output); +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<16>::ToAnsi(In begin, In end, Out output, char replacement, const std::locale& locale) +{ + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + output = Utf<32>::EncodeAnsi(codepoint, output, replacement, locale); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<16>::ToWide(In begin, In end, Out output, wchar_t replacement) +{ + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + output = Utf<32>::EncodeWide(codepoint, output, replacement); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<16>::ToLatin1(In begin, In end, Out output, char replacement) +{ + // Latin-1 is directly compatible with Unicode encodings, + // and can thus be treated as (a sub-range of) UTF-32 + while (begin < end) + { + *output++ = *begin < 256 ? static_cast<char>(*begin) : replacement; + begin++; + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<16>::ToUtf8(In begin, In end, Out output) +{ + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + output = Utf<8>::Encode(codepoint, output); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<16>::ToUtf16(In begin, In end, Out output) +{ + return std::copy(begin, end, output); +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<16>::ToUtf32(In begin, In end, Out output) +{ + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + *output++ = codepoint; + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In> +In Utf<32>::Decode(In begin, In /*end*/, Uint32& output, Uint32 /*replacement*/) +{ + output = *begin++; + return begin; +} + + +//////////////////////////////////////////////////////////// +template <typename Out> +Out Utf<32>::Encode(Uint32 input, Out output, Uint32 /*replacement*/) +{ + *output++ = input; + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In> +In Utf<32>::Next(In begin, In /*end*/) +{ + return ++begin; +} + + +//////////////////////////////////////////////////////////// +template <typename In> +std::size_t Utf<32>::Count(In begin, In end) +{ + return begin - end; +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<32>::FromAnsi(In begin, In end, Out output, const std::locale& locale) +{ + while (begin < end) + *output++ = DecodeAnsi(*begin++, locale); + + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<32>::FromWide(In begin, In end, Out output) +{ + while (begin < end) + *output++ = DecodeWide(*begin++); + + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<32>::FromLatin1(In begin, In end, Out output) +{ + // Latin-1 is directly compatible with Unicode encodings, + // and can thus be treated as (a sub-range of) UTF-32 + return std::copy(begin, end, output); +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<32>::ToAnsi(In begin, In end, Out output, char replacement, const std::locale& locale) +{ + while (begin < end) + output = EncodeAnsi(*begin++, output, replacement, locale); + + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<32>::ToWide(In begin, In end, Out output, wchar_t replacement) +{ + while (begin < end) + output = EncodeWide(*begin++, output, replacement); + + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<32>::ToLatin1(In begin, In end, Out output, char replacement) +{ + // Latin-1 is directly compatible with Unicode encodings, + // and can thus be treated as (a sub-range of) UTF-32 + while (begin < end) + { + *output++ = *begin < 256 ? static_cast<char>(*begin) : replacement; + begin++; + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<32>::ToUtf8(In begin, In end, Out output) +{ + while (begin < end) + output = Utf<8>::Encode(*begin++, output); + + return output; +} + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<32>::ToUtf16(In begin, In end, Out output) +{ + while (begin < end) + output = Utf<16>::Encode(*begin++, output); + + return output; +} + + +//////////////////////////////////////////////////////////// +template <typename In, typename Out> +Out Utf<32>::ToUtf32(In begin, In end, Out output) +{ + return std::copy(begin, end, output); +} + + +//////////////////////////////////////////////////////////// +template <typename In> +Uint32 Utf<32>::DecodeAnsi(In input, const std::locale& locale) +{ + // On Windows, GCC's standard library (glibc++) has almost + // no support for Unicode stuff. As a consequence, in this + // context we can only use the default locale and ignore + // the one passed as parameter. + + #if defined(SFML_SYSTEM_WINDOWS) && /* if Windows ... */ \ + (defined(__GLIBCPP__) || defined (__GLIBCXX__)) && /* ... and standard library is glibc++ ... */ \ + !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)) /* ... and STLPort is not used on top of it */ + + (void)locale; // to avoid warnings + + wchar_t character = 0; + mbtowc(&character, &input, 1); + return static_cast<Uint32>(character); + + #else + + // Get the facet of the locale which deals with character conversion + const std::ctype<wchar_t>& facet = std::use_facet< std::ctype<wchar_t> >(locale); + + // Use the facet to convert each character of the input string + return static_cast<Uint32>(facet.widen(input)); + + #endif +} + + +//////////////////////////////////////////////////////////// +template <typename In> +Uint32 Utf<32>::DecodeWide(In input) +{ + // The encoding of wide characters is not well defined and is left to the system; + // however we can safely assume that it is UCS-2 on Windows and + // UCS-4 on Unix systems. + // In both cases, a simple copy is enough (UCS-2 is a subset of UCS-4, + // and UCS-4 *is* UTF-32). + + return input; +} + + +//////////////////////////////////////////////////////////// +template <typename Out> +Out Utf<32>::EncodeAnsi(Uint32 codepoint, Out output, char replacement, const std::locale& locale) +{ + // On Windows, gcc's standard library (glibc++) has almost + // no support for Unicode stuff. As a consequence, in this + // context we can only use the default locale and ignore + // the one passed as parameter. + + #if defined(SFML_SYSTEM_WINDOWS) && /* if Windows ... */ \ + (defined(__GLIBCPP__) || defined (__GLIBCXX__)) && /* ... and standard library is glibc++ ... */ \ + !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)) /* ... and STLPort is not used on top of it */ + + (void)locale; // to avoid warnings + + char character = 0; + if (wctomb(&character, static_cast<wchar_t>(codepoint)) >= 0) + *output++ = character; + else if (replacement) + *output++ = replacement; + + return output; + + #else + + // Get the facet of the locale which deals with character conversion + const std::ctype<wchar_t>& facet = std::use_facet< std::ctype<wchar_t> >(locale); + + // Use the facet to convert each character of the input string + *output++ = facet.narrow(static_cast<wchar_t>(codepoint), replacement); + + return output; + + #endif +} + + +//////////////////////////////////////////////////////////// +template <typename Out> +Out Utf<32>::EncodeWide(Uint32 codepoint, Out output, wchar_t replacement) +{ + // The encoding of wide characters is not well defined and is left to the system; + // however we can safely assume that it is UCS-2 on Windows and + // UCS-4 on Unix systems. + // For UCS-2 we need to check if the source characters fits in (UCS-2 is a subset of UCS-4). + // For UCS-4 we can do a direct copy (UCS-4 *is* UTF-32). + + switch (sizeof(wchar_t)) + { + case 4: + { + *output++ = static_cast<wchar_t>(codepoint); + break; + } + + default: + { + if ((codepoint <= 0xFFFF) && ((codepoint < 0xD800) || (codepoint > 0xDFFF))) + { + *output++ = static_cast<wchar_t>(codepoint); + } + else if (replacement) + { + *output++ = replacement; + } + break; + } + } + + return output; +} diff --git a/source/libs/asura-lib-core/graphics/binding/_canvas.cpp b/source/libs/asura-lib-core/graphics/binding/_canvas.cpp new file mode 100644 index 0000000..7927995 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/binding/_canvas.cpp @@ -0,0 +1,46 @@ +#include "../canvas.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace Graphics + { + + LUAX_REGISTRY(Canvas) + { + LUAX_REGISTER_METHODS(state, + { "SetSize", _SetSize }, + { "Bind", _Bind }, + { "Unbind", _Unbind } + ); + } + + LUAX_POSTPROCESS(Canvas) + { + + } + + // canvas:SetSize() + LUAX_IMPL_METHOD(Canvas, _SetSize) + { + LUAX_PREPARE(L, Canvas); + + } + + // canvas:Bind() + LUAX_IMPL_METHOD(Canvas, _Bind) + { + LUAX_PREPARE(L, Canvas); + + } + + // canvas:Unbind() + LUAX_IMPL_METHOD(Canvas, _Unbind) + { + LUAX_PREPARE(L, Canvas); + + } + + } +} diff --git a/source/libs/asura-lib-core/graphics/binding/_color.cpp b/source/libs/asura-lib-core/graphics/binding/_color.cpp new file mode 100644 index 0000000..11e80a1 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/binding/_color.cpp @@ -0,0 +1,54 @@ +#include "../color.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace Graphics + { + + LUAX_REGISTRY(Color) + { + LUAX_REGISTER_METHODS(state, + { "ToColor32", _ToColor32 }, + { "SetColor", _SetColor }, + { "GetColor", _GetColor }, + { "Multiply", _Multiply } + ); + } + + LUAX_POSTPROCESS(Color) + { + + } + + // color:ToColor32() + LUAX_IMPL_METHOD(Color, _ToColor32) + { + LUAX_PREPARE(L, Color); + + } + + // color:SetColor() + LUAX_IMPL_METHOD(Color, _SetColor) + { + LUAX_PREPARE(L, Color); + + } + + // color:GetColor() + LUAX_IMPL_METHOD(Color, _GetColor) + { + LUAX_PREPARE(L, Color); + + } + + // color:Multiply() + LUAX_IMPL_METHOD(Color, _Multiply) + { + LUAX_PREPARE(L, Color); + + } + + } +} diff --git a/source/libs/asura-lib-core/graphics/binding/_color32.cpp b/source/libs/asura-lib-core/graphics/binding/_color32.cpp new file mode 100644 index 0000000..7095866 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/binding/_color32.cpp @@ -0,0 +1,86 @@ +#include "../color32.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace Graphics + { + + LUAX_REGISTRY(Color32) + { + LUAX_REGISTER_METHODS(state, + { "ToColor", _ToColor }, + { "GetRed", _GetRed }, + { "GetGreen", _GetGreen }, + { "GetBlue", _GetBlue }, + { "GetAlpha", _GetAlpha }, + { "Multiply", _Multiply }, + { "Index", _Index }, + { "NewIndex", _NewIndex } + ); + } + + LUAX_POSTPROCESS(Color32) + { + + } + + // color32:ToColor() + LUAX_IMPL_METHOD(Color32, _ToColor) + { + LUAX_PREPARE(L, Color32); + + } + + // color32:GetRed() + LUAX_IMPL_METHOD(Color32, _GetRed) + { + LUAX_PREPARE(L, Color32); + + } + + // color32:GetGreen() + LUAX_IMPL_METHOD(Color32, _GetGreen) + { + LUAX_PREPARE(L, Color32); + + } + + // color32:GetBlue() + LUAX_IMPL_METHOD(Color32, _GetBlue) + { + LUAX_PREPARE(L, Color32); + + } + + // color32:GetAlpha() + LUAX_IMPL_METHOD(Color32, _GetAlpha) + { + LUAX_PREPARE(L, Color32); + + } + + // color32:Multiply() + LUAX_IMPL_METHOD(Color32, _Multiply) + { + LUAX_PREPARE(L, Color32); + + } + + // color32:Index() + LUAX_IMPL_METHOD(Color32, _Index) + { + LUAX_PREPARE(L, Color32); + + } + + // color32:NewIndex() + LUAX_IMPL_METHOD(Color32, _NewIndex) + { + LUAX_PREPARE(L, Color32); + + } + + } +} diff --git a/source/libs/asura-lib-core/graphics/binding/_image.cpp b/source/libs/asura-lib-core/graphics/binding/_image.cpp new file mode 100644 index 0000000..cb008d3 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/binding/_image.cpp @@ -0,0 +1,99 @@ +#include "../image.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace Graphics + { + + LUAX_REGISTRY(Image) + { + LUAX_REGISTER_METHODS(state, + { "New", _New }, + { "Load", _Load }, + { "GetWidth", _GetWidth }, + { "GetHeight", _GetHeight }, + { "GetSize", _GetSize }, + { "GetPixel", _GetPixel }, + { "Render", _Render } + ); + } + + LUAX_POSTPROCESS(Image) + { + + } + + // image = Image.New() + LUAX_IMPL_METHOD(Image, _New) + { + LUAX_STATE(L); + + Image* image = new Image(); + image->PushLuaxUserdata(state); + return 0; + } + + // successed = image:Load(image_data) + LUAX_IMPL_METHOD(Image, _Load) + { + LUAX_PREPARE(L, Image); + + ImageData* imgdata = state.CheckUserdata<ImageData>(2); + bool loaded = self->Load(imgdata); + state.Push(loaded); + return 1; + } + + // width = image:GetWidth() + LUAX_IMPL_METHOD(Image, _GetWidth) + { + LUAX_PREPARE(L, Image); + + state.Push(self->GetWidth()); + return 1; + } + + // height = image:GetHeight() + LUAX_IMPL_METHOD(Image, _GetHeight) + { + LUAX_PREPARE(L, Image); + + state.Push(self->GetHeight()); + return 1; + } + + // w, h = image:GetSize() + LUAX_IMPL_METHOD(Image, _GetSize) + { + LUAX_PREPARE(L, Image); + + Math::Vector2u size = self->GetSize(); + state.Push(size.x); + state.Push(size.y); + return 2; + } + + // color32 = image:GetPixel(x, y) + LUAX_IMPL_METHOD(Image, _GetPixel) + { + LUAX_PREPARE(L, Image); + + uint x = state.CheckValue<uint>(2); + uint y = state.CheckValue<uint>(3); + Color32* c32 = new Color32(self->GetPixel(x, y)); + c32->PushLuaxUserdata(state); + return 1; + } + + // image:Render() + LUAX_IMPL_METHOD(Image, _Render) + { + LUAX_PREPARE(L, Image); + + return 0; + } + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-core/graphics/binding/_image_data.cpp b/source/libs/asura-lib-core/graphics/binding/_image_data.cpp new file mode 100644 index 0000000..3ff38f9 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/binding/_image_data.cpp @@ -0,0 +1,70 @@ +#include "../image_data.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace Graphics + { + + LUAX_REGISTRY(ImageData) + { + LUAX_REGISTER_METHODS(state, + { "New", _New }, + { "GetPixel", _GetPixel }, + { "GetSize", _GetSize }, + { "GetWidth", _GetWidth }, + { "GetHeight", _GetHeight }, + { "GetPixelFormat", _GetPixelFormat } + ); + } + + LUAX_POSTPROCESS(ImageData) + { + + } + + // ImageData.New() + LUAX_IMPL_METHOD(ImageData, _New) + { + LUAX_STATE(L); + + } + + // imagedata:GetPixel() + LUAX_IMPL_METHOD(ImageData, _GetPixel) + { + LUAX_PREPARE(L, ImageData); + + } + + // imagedata:GetSize() + LUAX_IMPL_METHOD(ImageData, _GetSize) + { + LUAX_PREPARE(L, ImageData); + + } + + // imagedata:GetWidth() + LUAX_IMPL_METHOD(ImageData, _GetWidth) + { + LUAX_PREPARE(L, ImageData); + + } + + // imagedata:GetHeight() + LUAX_IMPL_METHOD(ImageData, _GetHeight) + { + LUAX_PREPARE(L, ImageData); + + } + + // imagedata:GetPixelFormat() + LUAX_IMPL_METHOD(ImageData, _GetPixelFormat) + { + LUAX_PREPARE(L, ImageData); + + } + + } +} diff --git a/source/modules/asura-core/graphics/binding/_image_decode_task.cpp b/source/libs/asura-lib-core/graphics/binding/_image_decode_task.cpp index 76b544b..76b544b 100644 --- a/source/modules/asura-core/graphics/binding/_image_decode_task.cpp +++ b/source/libs/asura-lib-core/graphics/binding/_image_decode_task.cpp diff --git a/source/libs/asura-lib-core/graphics/binding/_mesh2d.cpp b/source/libs/asura-lib-core/graphics/binding/_mesh2d.cpp new file mode 100644 index 0000000..07e9f12 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/binding/_mesh2d.cpp @@ -0,0 +1,21 @@ +#include "../mesh2d.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace Graphics + { + + LUAX_REGISTRY(Mesh2D) + { + + } + + LUAX_POSTPROCESS(Mesh2D) + { + + } + + } +} diff --git a/source/libs/asura-lib-core/graphics/binding/_shader.cpp b/source/libs/asura-lib-core/graphics/binding/_shader.cpp new file mode 100644 index 0000000..a06e54b --- /dev/null +++ b/source/libs/asura-lib-core/graphics/binding/_shader.cpp @@ -0,0 +1,126 @@ +#include "../shader.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace Graphics + { + + LUAX_REGISTRY(Shader) + { + LUAX_REGISTER_METHODS(state, + { "New", _New }, + { "Use", _Use }, + { "Unuse", _Unuse }, + { "Load", _Load }, + { "HasUniform", _HasUniform }, + { "GetUniformLocation", _GetUniformLocation }, + { "SetBuiltInUniforms", _SetBuiltInUniforms }, + { "SetUniformFloat", _SetUniformFloat }, + { "SetUniformTexture", _SetUniformTexture }, + { "SetUniformVector2", _SetUniformVector2 }, + { "SetUniformVector3", _SetUniformVector3 }, + { "SetUniformVector4", _SetUniformVector4 }, + { "SetUniformColor", _SetUniformColor } + ); + } + + LUAX_POSTPROCESS(Shader) + { + + } + + // Shader.New() + LUAX_IMPL_METHOD(Shader, _New) + { + LUAX_STATE(L); + + } + + // shader:Use() + LUAX_IMPL_METHOD(Shader, _Use) + { + LUAX_PREPARE(L, Shader); + + } + + // shader:Unuse() + LUAX_IMPL_METHOD(Shader, _Unuse) + { + LUAX_PREPARE(L, Shader); + + } + + // shader:Load() + LUAX_IMPL_METHOD(Shader, _Load) + { + LUAX_PREPARE(L, Shader); + + } + + // shader:HasUniform() + LUAX_IMPL_METHOD(Shader, _HasUniform) + { + LUAX_PREPARE(L, Shader); + + } + + // shader:GetUniformLocation() + LUAX_IMPL_METHOD(Shader, _GetUniformLocation) + { + LUAX_PREPARE(L, Shader); + + } + + // shader:SetBuiltInUniforms() + LUAX_IMPL_METHOD(Shader, _SetBuiltInUniforms) + { + LUAX_PREPARE(L, Shader); + + } + + // shader:SetUniformFloat() + LUAX_IMPL_METHOD(Shader, _SetUniformFloat) + { + LUAX_PREPARE(L, Shader); + + } + + // shader:SetUniformTexture() + LUAX_IMPL_METHOD(Shader, _SetUniformTexture) + { + LUAX_PREPARE(L, Shader); + + } + + // shader:SetUniformVector2() + LUAX_IMPL_METHOD(Shader, _SetUniformVector2) + { + LUAX_PREPARE(L, Shader); + + } + + // shader:SetUniformVector3() + LUAX_IMPL_METHOD(Shader, _SetUniformVector3) + { + LUAX_PREPARE(L, Shader); + + } + + // shader:SetUniformVector4() + LUAX_IMPL_METHOD(Shader, _SetUniformVector4) + { + LUAX_PREPARE(L, Shader); + + } + + // shader:SetUniformColor() + LUAX_IMPL_METHOD(Shader, _SetUniformColor) + { + LUAX_PREPARE(L, Shader); + + } + + } +} diff --git a/source/libs/asura-lib-core/graphics/binding/_sprite_batch.cpp b/source/libs/asura-lib-core/graphics/binding/_sprite_batch.cpp new file mode 100644 index 0000000..8556c02 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/binding/_sprite_batch.cpp @@ -0,0 +1,21 @@ +#include "../sprite_batch.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace Graphics + { + + LUAX_REGISTRY(SpriteBatch) + { + + } + + LUAX_POSTPROCESS(SpriteBatch) + { + + } + + } +} diff --git a/source/libs/asura-lib-core/graphics/binding/_window.cpp b/source/libs/asura-lib-core/graphics/binding/_window.cpp new file mode 100644 index 0000000..fc74d6c --- /dev/null +++ b/source/libs/asura-lib-core/graphics/binding/_window.cpp @@ -0,0 +1,103 @@ +#include "../window.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace Graphics + { + + LUAX_REGISTRY(Window) + { + LUAX_REGISTER_METHODS(state, + { "Show", _Show }, + { "Hide", _Hide }, + { "SetResolution", _SetResolution }, + { "SetFullScreen", _SetFullScreen }, + { "SetTitle", _SetTitle }, + { "SetWindowStyle", _SetWindowStyle }, + { "Clear", _Clear }, + { "Draw", _Draw }, + { "SwapRenderBuffer", _SwapRenderBuffer } + ); + } + + LUAX_POSTPROCESS(Window) + { + + } + + // window:Show() + LUAX_IMPL_METHOD(Window, _Show) + { + LUAX_PREPARE(L, Window); + + return 0; + } + + // window:Hide() + LUAX_IMPL_METHOD(Window, _Hide) + { + LUAX_PREPARE(L, Window); + + return 0; + } + + // window:SetResolution() + LUAX_IMPL_METHOD(Window, _SetResolution) + { + LUAX_PREPARE(L, Window); + + return 0; + } + + // window:SetFullScreen() + LUAX_IMPL_METHOD(Window, _SetFullScreen) + { + LUAX_PREPARE(L, Window); + + return 0; + } + + // window:SetTitle() + LUAX_IMPL_METHOD(Window, _SetTitle) + { + LUAX_PREPARE(L, Window); + + return 0; + } + + // window:SetWindowStyle() + LUAX_IMPL_METHOD(Window, _SetWindowStyle) + { + LUAX_PREPARE(L, Window); + + return 0; + } + + // window:Clear() + LUAX_IMPL_METHOD(Window, _Clear) + { + LUAX_PREPARE(L, Window); + + return 0; + } + + // window:Draw() + LUAX_IMPL_METHOD(Window, _Draw) + { + LUAX_PREPARE(L, Window); + + return 0; + } + + // window:SwapRenderBuffer() + LUAX_IMPL_METHOD(Window, _SwapRenderBuffer) + { + LUAX_PREPARE(L, Window); + + return 0; + } + + } +} diff --git a/source/libs/asura-lib-core/graphics/blend_mode.h b/source/libs/asura-lib-core/graphics/blend_mode.h new file mode 100644 index 0000000..775cc45 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/blend_mode.h @@ -0,0 +1,17 @@ +#ifndef __ASURA_ENGINE_BLEND_MODE_H__ +#define __ASURA_ENGINE_BLEND_MODE_H__ + +namespace AsuraEngine +{ + namespace Graphics + { + + enum BlendMode + { + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/graphics/canvas.cpp b/source/libs/asura-lib-core/graphics/canvas.cpp new file mode 100644 index 0000000..61787b6 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/canvas.cpp @@ -0,0 +1,41 @@ +#include "Canvas.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + Canvas::Canvas() + : Texture() + , mWidth(0) + , mHeight(0) + { + glGenFramebuffers(1, &mFBO); + GLint current_fbo; + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo); + glBindFramebuffer(GL_FRAMEBUFFER, mFBO); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTextureHandle, 0); + glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); + } + + void Canvas::SetSize(uint w, uint h) + { + GLint current_tex; + glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_tex); + glBindTexture(GL_TEXTURE_2D, mTextureHandle); + + glBindTexture(GL_TEXTURE_2D, current_tex); + } + + void Canvas::Bind() + { + + } + + void Canvas::Unbind() + { + + } + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-core/graphics/canvas.h b/source/libs/asura-lib-core/graphics/canvas.h new file mode 100644 index 0000000..5b188ca --- /dev/null +++ b/source/libs/asura-lib-core/graphics/canvas.h @@ -0,0 +1,83 @@ +#ifndef __ASURA_ENGINE_CANVAS_H__ +#define __ASURA_ENGINE_CANVAS_H__ + +#include <asura-lib-utils/scripting/portable.hpp> +#include <asura-lib-utils/math/rect.hpp> +#include <asura-lib-utils/math/vector2.hpp> + +#include "gl.h" +#include "texture.h" +#include "render_target.h" +#include "render_state.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + /// + /// CanvasҲԳΪrender textureҲΪtextureȾ + /// + class Canvas ASURA_FINAL + : public Drawable + , public RenderTarget + , public Scripting::Portable<Canvas> + { + public: + + Canvas(); + + ~Canvas(); + + /// + /// render textureĴС + /// + void SetSize(uint w, uint h); + + void Clear(const Color& col = Color::Black) override; + + void Clear(const Math::Recti& quad, const Color& col = Color::Black) override; + + void Render(const RenderTarget* rt, const Math::Vector2i& pos, const Math::Vector2i& scale, const Math::Vector2i& center, float rot); + + void Render(const RenderTarget* rt, const Math::Rectf& quad, const Math::Vector2i& pos, const Math::Vector2i& scale, const Math::Vector2i& center, float rot); + + void Draw(const Drawable* texture, const RenderState& state); + + void Draw(const Drawable* texture, const Math::Recti& quad, const RenderState& state); + + private: + + /// + /// Frame buffer object id. + /// + GLuint mFBO; + + /// + /// canvasĴС + /// + uint mWidth, mHeight; + + public: + + //---------------------------------------------------------------------------------------------------------- + + LUAX_DECL_FACTORY(SimCanvas); + + LUAX_DECL_METHOD(_SetSize); + LUAX_DECL_METHOD(_Bind); + LUAX_DECL_METHOD(_Unbind); + + //---------------------------------------------------------------------------------------------------------- + + }; + + /// + /// CanvasΪRenderTexture + /// + using RenderTexture = Canvas; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/graphics/color.cpp b/source/libs/asura-lib-core/graphics/color.cpp new file mode 100644 index 0000000..4d3691e --- /dev/null +++ b/source/libs/asura-lib-core/graphics/color.cpp @@ -0,0 +1,47 @@ +#include "color.h" +#include "color32.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + Color::Color() + { + r = g = b = a = 0; + } + + Color::Color(const Color& c) + { + r = c.r; + g = c.g; + b = c.b; + a = c.a; + } + + Color::Color(float r, float g, float b, float a) + { + this->r = r; + this->g = g; + this->b = b; + this->a = a; + } + + Color::Color(const Color32& c) + { + r = c.r / 255.f; + g = c.g / 255.f; + b = c.b / 255.f; + a = c.a / 255.f; + } + + Color Color::operator *(const Color& c) + { + r *= c.r; + g *= c.g; + b *= c.b; + a *= c.a; + } + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-core/graphics/color.h b/source/libs/asura-lib-core/graphics/color.h new file mode 100644 index 0000000..607314b --- /dev/null +++ b/source/libs/asura-lib-core/graphics/color.h @@ -0,0 +1,55 @@ +#ifndef __ASURA_ENGINE_COLOR_H__ +#define __ASURA_ENGINE_COLOR_H__ + +#include <asura-lib-utils/scripting/portable.hpp> + +#include "../core_config.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + class Color32; + + /// + /// 淶ɫ + /// + class Color ASURA_FINAL + : public Scripting::Portable<Color> + { + public: + + static Color Black; + static Color White; + static Color Red; + static Color Green; + static Color Blue; + + Color(); + + Color(const Color& c); + + Color(float r, float g, float b, float a); + + Color(const Color32& c); + + ~Color(); + + Color operator *(const Color& c); + + float r, g, b, a; + + LUAX_DECL_FACTORY(Color); + + LUAX_DECL_METHOD(_ToColor32); + LUAX_DECL_METHOD(_SetColor); + LUAX_DECL_METHOD(_GetColor); + LUAX_DECL_METHOD(_Multiply); // ɫ˷ + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/graphics/color32.cpp b/source/libs/asura-lib-core/graphics/color32.cpp new file mode 100644 index 0000000..0ebc77c --- /dev/null +++ b/source/libs/asura-lib-core/graphics/color32.cpp @@ -0,0 +1,39 @@ +#include "color.h" +#include "color32.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + Color32::Color32() + { + r = g = b = a = 0; + } + + Color32::Color32(const Color32& c) + { + r = c.r; + g = c.g; + b = c.b; + a = c.a; + } + + Color32::Color32(const Color& c) + { + r = 255.f * c.r; + g = 255.f * c.g; + b = 255.f * c.b; + a = 255.f * c.a; + } + + Color32::Color32(byte r, byte g, byte b, byte a) + { + this->r = r; + this->g = g; + this->b = b; + this->a = a; + } + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-core/graphics/color32.h b/source/libs/asura-lib-core/graphics/color32.h new file mode 100644 index 0000000..c64a9b9 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/color32.h @@ -0,0 +1,51 @@ +#ifndef __ASURA_ENGINE_COLOR32_H__ +#define __ASURA_ENGINE_COLOR32_H__ + +#include <asura-lib-utils/scripting/portable.hpp> + +#include "../core_config.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + class Color; + + /// + /// 32bitsɫ + /// + class Color32 ASURA_FINAL + : public Scripting::Portable<Color32> + { + public: + + LUAX_DECL_FACTORY(Color32); + + Color32(); + + ~Color32(); + + Color32(const Color32& c); + + Color32(const Color& c); + + Color32(byte r, byte g, byte b, byte a); + + byte r, g, b, a; + + LUAX_DECL_METHOD(_ToColor); + LUAX_DECL_METHOD(_GetRed); + LUAX_DECL_METHOD(_GetGreen); + LUAX_DECL_METHOD(_GetBlue); + LUAX_DECL_METHOD(_GetAlpha); + LUAX_DECL_METHOD(_Multiply); + LUAX_DECL_METHOD(_Index); //r,g,b,a + LUAX_DECL_METHOD(_NewIndex); //r,g,b,a + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/wnd/window_impl_glew.cpp b/source/libs/asura-lib-core/graphics/color_palette.h index e69de29..e69de29 100644 --- a/source/modules/asura-core/wnd/window_impl_glew.cpp +++ b/source/libs/asura-lib-core/graphics/color_palette.h diff --git a/source/modules/asura-core/wnd/window_impl_glew.h b/source/libs/asura-lib-core/graphics/gif.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-core/wnd/window_impl_glew.h +++ b/source/libs/asura-lib-core/graphics/gif.cpp diff --git a/source/libs/asura-lib-core/graphics/gif.h b/source/libs/asura-lib-core/graphics/gif.h new file mode 100644 index 0000000..8b89858 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/gif.h @@ -0,0 +1,20 @@ +#ifndef __ASURA_GIF_H__ +#define __ASURA_GIF_H__ + +namespace AsuraEngine +{ + namespace Graphics + { + + /// + /// Gif + /// + class Gif + { + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/graphics/gl.cpp b/source/libs/asura-lib-core/graphics/gl.cpp new file mode 100644 index 0000000..7c68c8f --- /dev/null +++ b/source/libs/asura-lib-core/graphics/gl.cpp @@ -0,0 +1,25 @@ +#include "../core_config.h" +#include "gl.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + bool OpenGL::instantiated = false; + + // + OpenGL gl; + + OpenGL::OpenGL() + { + ASSERT(!instantiated); + instantiated = true; + } + + OpenGL::~OpenGL() + { + } + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-core/graphics/gl.h b/source/libs/asura-lib-core/graphics/gl.h new file mode 100644 index 0000000..bfc60ea --- /dev/null +++ b/source/libs/asura-lib-core/graphics/gl.h @@ -0,0 +1,41 @@ +#ifndef __ASURA_ENGINE_OPENGL_H__ +#define __ASURA_ENGINE_OPENGL_H__ + +#include "glad/glad.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + class Profiler; + + /// + /// һЩopengl״̬١ + /// + class OpenGL + { + public: + OpenGL(); + ~OpenGL(); + + private: + + friend class Profiler; + + /// + /// opengl + /// + static bool instantiated; + + }; + + /// + /// OpenGL + /// + extern OpenGL gl; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/graphics/image.cpp b/source/libs/asura-lib-core/graphics/image.cpp new file mode 100644 index 0000000..e704945 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/image.cpp @@ -0,0 +1,32 @@ +#include "Config.h" +#include "Image.h" +#include "GL.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + Image::Image() + { + } + + Image::~Image() + { + } + + //\Ϣ + bool Image::Load(ImageData* data) + { + ASSERT(data); + + glBindTexture(GL_TEXTURE_2D, mTextureHandle); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, data->width, data->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data->pixels); + glBindTexture(GL_TEXTURE_2D, 0); + return true; + + RRA(data, mImageData); + } + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-core/graphics/image.h b/source/libs/asura-lib-core/graphics/image.h new file mode 100644 index 0000000..4d9787b --- /dev/null +++ b/source/libs/asura-lib-core/graphics/image.h @@ -0,0 +1,83 @@ +#ifndef __ASURA_ENGINE_IMAGE_H__ +#define __ASURA_ENGINE_IMAGE_H__ + +#include <asura-lib-utils/math/rect.hpp> +#include <asura-lib-utils/math/vector2.hpp> +#include <asura-lib-utils/scripting/portable.hpp> +#include <asura-lib-utils/io/reloadable.h> +#include <asura-lib-utils/stringmap.hpp> +#include <asura-lib-utils/manager.hpp> + +#include "texture.h" +#include "color.h" +#include "color32.h" +#include "image_data.h" +#include "render_state.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + class ImageFactory; + + /// + /// ImageͼƬڴȡϷĽһImageڴ桢Դֻᱣһ + /// ݣҪimageêλãźתǶȣʹsprite + /// һֻࡣҪǿǵeditorengineʹòͬķװ + /// + class Image ASURA_FINAL + : public Drawable + , public Scripting::Portable<Image> + , public AEIO::Reloadable + { + public: + + LUAX_DECL_FACTORY(SimImage); + + Image(); + + ~Image(); + + /// + /// bufferimageϢmPixelsΪգݡ¹image + /// ʹglTexImage2Dύimageݡ + /// + bool Load(ImageData* data); + + uint GetWidth(); + uint GetHeight(); + Math::Vector2u GetSize(); + + /// + /// ijһλõ + /// + Color32 GetPixel(uint x, uint y); + + void Render(const RenderTarget* rt, const RenderState& state) override; + + void Render(const RenderTarget* rt, const Math::Rectf& quad, const RenderState& state) override; + + private: + + ImageData* mImageData; + Luax::LuaxMemberRef mImageDataRef; + + Math::Vector2u mSize; + + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_Load); + LUAX_DECL_METHOD(_GetWidth); + LUAX_DECL_METHOD(_GetHeight); + LUAX_DECL_METHOD(_GetSize); + LUAX_DECL_METHOD(_GetPixel); + LUAX_DECL_METHOD(_Render); + + }; + + } +} + +namespace AEGraphics = AsuraEngine::Graphics; + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/graphics/image_data.cpp b/source/libs/asura-lib-core/graphics/image_data.cpp new file mode 100644 index 0000000..b79dfab --- /dev/null +++ b/source/libs/asura-lib-core/graphics/image_data.cpp @@ -0,0 +1,51 @@ +#include "image_data.h" +#include "png_decoder.h" +#include "stb_decoder.h" +#include "image_decoder.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + using namespace std; + + // imagedecoderΪԡ + list<ImageDecoder*> ImageData::ImageDecoders = { + new PNGDecoder(), // png + new STBDecoder() // jpeg, tga, bmp + }; + + ImageData::ImageData(const IO::DataBuffer& buffer) + : DecodedData(buffer) + { + } + + ImageData::~ImageData() + { + if (pixels) + delete[] pixels; + } + + /// + /// ɹ׳쳣 + /// + void ImageData::Decode(const IO::DataBuffer& buffer) + { + for (ImageDecoder* decoder : ImageDecoders) + { + if (decoder->CanDecode(buffer)) + { + decoder->Decode(buffer, *this); + return; + } + } + } + + Color ImageData::GetPixel(uint x, uint y) + { + + } + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-core/graphics/image_data.h b/source/libs/asura-lib-core/graphics/image_data.h new file mode 100644 index 0000000..820e276 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/image_data.h @@ -0,0 +1,68 @@ +#ifndef __ASURA_ENGINE_IMAGEDATA_H__ +#define __ASURA_ENGINE_IMAGEDATA_H__ + +#include <list> + +#include <asura-lib-utils/scripting/portable.hpp> +#include <asura-lib-utils/io/decoded_data.h> +#include <asura-lib-utils/io/data_buffer.h> +#include <asura-lib-utils/threading/thread.h> + +#include "pixel_format.h" +#include "color.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + class ImageDecoder; + + class ImageData ASURA_FINAL + : public AEIO::DecodedData + , public Scripting::Portable<ImageData> + { + public: + + LUAX_DECL_FACTORY(ImageData); + + /// + /// ͼƬļϢʧܣ׳쳣 + /// + ImageData(const AEIO::DataBuffer& buffer); + ~ImageData(); + + void Load(const AEIO::DataBuffer& buffer); + void LoadAsync(const AEIO::DataBuffer& buffer, AEThreading::Thread* thread); + + Color GetPixel(uint x, uint y); + + uint width, height; + PixelFormat format; + std::size_t size; + byte* pixels; + + private: + + void Decode(const AEIO::DataBuffer& buffer) override; + + /// + /// ڵһimage dataʱṩdecoderڼdecodersмѡԡ + /// + static std::list<ImageDecoder*> ImageDecoders; + + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_GetPixel); + LUAX_DECL_METHOD(_GetSize); + LUAX_DECL_METHOD(_GetWidth); + LUAX_DECL_METHOD(_GetHeight); + LUAX_DECL_METHOD(_GetPixelFormat); + + }; + + } +} + +namespace AEGraphics = AsuraEngine::Graphics; + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/wnd/window_impl_glut.cpp b/source/libs/asura-lib-core/graphics/image_decode_task.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-core/wnd/window_impl_glut.cpp +++ b/source/libs/asura-lib-core/graphics/image_decode_task.cpp diff --git a/source/libs/asura-lib-core/graphics/image_decode_task.h b/source/libs/asura-lib-core/graphics/image_decode_task.h new file mode 100644 index 0000000..a721b3e --- /dev/null +++ b/source/libs/asura-lib-core/graphics/image_decode_task.h @@ -0,0 +1,25 @@ +#ifndef __ASURA_IMAGE_DECODE_TASK_H__ +#define __ASURA_IMAGE_DECODE_TASK_H__ + +#include <asura-lib-utils/threading/thread_task.h> +#include <asura-lib-utils/scripting/portable.hpp> + +namespace AsuraEngine +{ + namespace Graphics + { + + class ImageDecodeTask + : public AEScripting::Portable<ImageDecodeTask> + , public AEThreading::ThreadTask + { + public: + + LUAX_DECL_FACTORY(ImageDecodeTask); + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/graphics/image_decoder.h b/source/libs/asura-lib-core/graphics/image_decoder.h new file mode 100644 index 0000000..6f2049a --- /dev/null +++ b/source/libs/asura-lib-core/graphics/image_decoder.h @@ -0,0 +1,35 @@ +#ifndef __ASURA_ENGINE_IMAGE_DECODER_H__ +#define __ASURA_ENGINE_IMAGE_DECODER_H__ + +#include <asura-lib-utils/io/data_buffer.h> + +#include "image_data.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + class ImageDecoder + { + public: + + ImageDecoder(); + virtual ~ImageDecoder(); + + /// + /// жڴǷñdecoderѹ + /// + virtual bool CanDecode(const AEIO::DataBuffer& buffer) = 0; + + /// + /// һڴ棬һѹImage dataѹʧܷnullptr + /// + virtual void Decode(const AEIO::DataBuffer& buffer, ImageData& data) = 0; + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-core/wnd/window_impl_glut.h b/source/libs/asura-lib-core/graphics/mesh2d.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-core/wnd/window_impl_glut.h +++ b/source/libs/asura-lib-core/graphics/mesh2d.cpp diff --git a/source/libs/asura-lib-core/graphics/mesh2d.h b/source/libs/asura-lib-core/graphics/mesh2d.h new file mode 100644 index 0000000..48b461d --- /dev/null +++ b/source/libs/asura-lib-core/graphics/mesh2d.h @@ -0,0 +1,28 @@ +#ifndef __ASURA_ENGINE_MESH2D_H__ +#define __ASURA_ENGINE_MESH2D_H__ + +#include <asura-lib-utils/scripting/portable.hpp> + +namespace AsuraEngine +{ + namespace Graphics + { + + /// + /// 2D meshһЩ㶯 + /// + class Mesh2D ASURA_FINAL + : public Scripting::Portable<Mesh2D> + { + public: + + Mesh2D(); + + ~Mesh2D(); + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-utils/threading/thread_task.cpp b/source/libs/asura-lib-core/graphics/mesh2d_data.cpp index e69de29..e69de29 100644 --- a/source/modules/asura-utils/threading/thread_task.cpp +++ b/source/libs/asura-lib-core/graphics/mesh2d_data.cpp diff --git a/source/libs/asura-lib-core/graphics/mesh2d_data.h b/source/libs/asura-lib-core/graphics/mesh2d_data.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/mesh2d_data.h diff --git a/source/libs/asura-lib-core/graphics/pixel_format.h b/source/libs/asura-lib-core/graphics/pixel_format.h new file mode 100644 index 0000000..8df07d5 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/pixel_format.h @@ -0,0 +1,91 @@ +namespace AsuraEngine +{ + namespace Graphics + { + + /// + /// ظʽ + /// + enum PixelFormat + { + PIXELFORMAT_UNKNOWN, + + // these are converted to an actual format by love + PIXELFORMAT_NORMAL, + PIXELFORMAT_HDR, + + // "regular" formats + PIXELFORMAT_R8, + PIXELFORMAT_RG8, + PIXELFORMAT_RGBA8, + PIXELFORMAT_sRGBA8, + PIXELFORMAT_R16, + PIXELFORMAT_RG16, + PIXELFORMAT_RGBA16, + PIXELFORMAT_R16F, + PIXELFORMAT_RG16F, + PIXELFORMAT_RGBA16F, + PIXELFORMAT_R32F, + PIXELFORMAT_RG32F, + PIXELFORMAT_RGBA32F, + + PIXELFORMAT_LA8, // Same as RG8, but accessed as (L, L, L, A) + + // packed formats + PIXELFORMAT_RGBA4, + PIXELFORMAT_RGB5A1, + PIXELFORMAT_RGB565, + PIXELFORMAT_RGB10A2, + PIXELFORMAT_RG11B10F, + + // depth/stencil formats + PIXELFORMAT_STENCIL8, + PIXELFORMAT_DEPTH16, + PIXELFORMAT_DEPTH24, + PIXELFORMAT_DEPTH32F, + PIXELFORMAT_DEPTH24_STENCIL8, + PIXELFORMAT_DEPTH32F_STENCIL8, + + // compressed formats + PIXELFORMAT_DXT1, + PIXELFORMAT_DXT3, + PIXELFORMAT_DXT5, + PIXELFORMAT_BC4, + PIXELFORMAT_BC4s, + PIXELFORMAT_BC5, + PIXELFORMAT_BC5s, + PIXELFORMAT_BC6H, + PIXELFORMAT_BC6Hs, + PIXELFORMAT_BC7, + PIXELFORMAT_PVR1_RGB2, + PIXELFORMAT_PVR1_RGB4, + PIXELFORMAT_PVR1_RGBA2, + PIXELFORMAT_PVR1_RGBA4, + PIXELFORMAT_ETC1, + PIXELFORMAT_ETC2_RGB, + PIXELFORMAT_ETC2_RGBA, + PIXELFORMAT_ETC2_RGBA1, + PIXELFORMAT_EAC_R, + PIXELFORMAT_EAC_Rs, + PIXELFORMAT_EAC_RG, + PIXELFORMAT_EAC_RGs, + PIXELFORMAT_ASTC_4x4, + PIXELFORMAT_ASTC_5x4, + PIXELFORMAT_ASTC_5x5, + PIXELFORMAT_ASTC_6x5, + PIXELFORMAT_ASTC_6x6, + PIXELFORMAT_ASTC_8x5, + PIXELFORMAT_ASTC_8x6, + PIXELFORMAT_ASTC_8x8, + PIXELFORMAT_ASTC_10x5, + PIXELFORMAT_ASTC_10x6, + PIXELFORMAT_ASTC_10x8, + PIXELFORMAT_ASTC_10x10, + PIXELFORMAT_ASTC_12x10, + PIXELFORMAT_ASTC_12x12, + + PIXELFORMAT_MAX_ENUM + }; + + } +} diff --git a/source/libs/asura-lib-core/graphics/png_decoder.cpp b/source/libs/asura-lib-core/graphics/png_decoder.cpp new file mode 100644 index 0000000..f919090 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/png_decoder.cpp @@ -0,0 +1,19 @@ +#include "PNGDecoder.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + bool PNGDecoder::CanDecode(const Filesystem::DataBuffer& buffer) + { + return false; + } + + void PNGDecoder::Decode(const Filesystem::DataBuffer& buffer, ImageData& data) + { + + } + + } +} diff --git a/source/libs/asura-lib-core/graphics/png_decoder.h b/source/libs/asura-lib-core/graphics/png_decoder.h new file mode 100644 index 0000000..bc871fa --- /dev/null +++ b/source/libs/asura-lib-core/graphics/png_decoder.h @@ -0,0 +1,27 @@ +#ifndef __ASURA_ENGINE_PNGDECODER_H__ +#define __ASURA_ENGINE_PNGDECODER_H__ + +#include "image_decoder.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + /// + /// ʹlodepngѹpngļ + /// + class PNGDecoder ASURA_FINAL: public ImageDecoder + { + public: + + bool CanDecode(const AEIO::DataBuffer& buffer) override; + + void Decode(const AEIO::DataBuffer& buffer, ImageData& data) override; + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/graphics/quad.cpp b/source/libs/asura-lib-core/graphics/quad.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/quad.cpp diff --git a/source/libs/asura-lib-core/graphics/quad.h b/source/libs/asura-lib-core/graphics/quad.h new file mode 100644 index 0000000..b7dd3d9 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/quad.h @@ -0,0 +1 @@ +// Quadrectڣrectǵıƫᣬquadһ diff --git a/source/libs/asura-lib-core/graphics/render_state.h b/source/libs/asura-lib-core/graphics/render_state.h new file mode 100644 index 0000000..4d1831c --- /dev/null +++ b/source/libs/asura-lib-core/graphics/render_state.h @@ -0,0 +1,49 @@ +#ifndef __ASURA_ENGINE_RENDER_STATE_H__ +#define __ASURA_ENGINE_RENDER_STATE_H__ + +#include <asura-lib-utils/math/vector2.hpp> +#include <asura-lib-utils/math/transform.h> + +#include "Shader.h" +#include "blend_mode.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + /// + /// Ⱦǰķʽ + /// + struct RenderState ASURA_FINAL + { + /// + /// Ĭϵrender state + /// + static RenderState Default; + + RenderState(); + ~RenderState(); + + /// + /// λášλúת + /// + + Math::Transform transform; + + /// + /// ɫ + /// + Shader* shader; + + /// + /// Ϸʽ + /// + BlendMode blendMode; + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/graphics/render_target.cpp b/source/libs/asura-lib-core/graphics/render_target.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/render_target.cpp diff --git a/source/libs/asura-lib-core/graphics/render_target.h b/source/libs/asura-lib-core/graphics/render_target.h new file mode 100644 index 0000000..afa5c6a --- /dev/null +++ b/source/libs/asura-lib-core/graphics/render_target.h @@ -0,0 +1,56 @@ +#ifndef __ASURA_ENGINE_RENDERTARGET_H__ +#define __ASURA_ENGINE_RENDERTARGET_H__ + +#include <asura-lib-utils/math/vector2.hpp> +#include <asura-lib-utils/math/rect.hpp> +#include <asura-lib-utils/scripting/portable.hpp> + +#include "texture.h" +#include "color.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + class Drawable; + + /// + /// ɱΪȾĿ࣬ + /// Canvas(RenderTexture) + /// Window(RenderWindow) + /// + class RenderTarget + { + public: + + RenderTarget() {}; + + virtual ~RenderTarget() {}; + + /// + /// ɫcolRT + /// + virtual void Clear(const Color& col = Color::Black) = 0; + + /// + /// ɫcolղRT + /// + virtual void Clear(const Math::Recti& quad, const Color& col = Color::Black) = 0; + + /// + /// textureRT + /// + virtual void Draw(const Drawable* texture, const RenderState& state) = 0; + + /// + /// һtextureRT + /// + virtual void Draw(const Drawable* texture, const Math::Recti& quad, const RenderState& state) = 0; + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/graphics/shader.cpp b/source/libs/asura-lib-core/graphics/shader.cpp new file mode 100644 index 0000000..1a85866 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/shader.cpp @@ -0,0 +1,81 @@ +#include "Shader.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + Shader::Shader() + { + + } + + Shader::~Shader() + { + + } + + bool Shader::Load(const std::string& vertexShader, const std::string& fragmentShader) + { + + } + + uint Shader::GetUniformLocation(const std::string& uniform) + { + + } + + GLuint Shader::GetGLProgramHandle() + { + return mProgramHandle; + } + + void Shader::Use() + { + + } + + void Shader::Unuse() + { + + } + + void Shader::SetUniformFloat(uint loc, float value) + { + + } + + void Shader::SetUniformFloat(uint loc, float value) + { + + } + + void Shader::SetUniformTexture(uint loc, const Texture& texture) + { + + } + + void Shader::SetUniformVector2(uint loc, const Math::Vector2f& vec2) + { + + } + + void Shader::SetUniformVector3(uint loc, const Math::Vector3f& vec3) + { + + } + + void Shader::SetUniformVector4(uint loc, const Math::Vector4f& vec4) + { + + } + + uint Shader::GetGLTextureUnitCount() + { + GLint maxTextureUnits = 0; + glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits); + return (uint)maxTextureUnits; + } + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-core/graphics/shader.h b/source/libs/asura-lib-core/graphics/shader.h new file mode 100644 index 0000000..1c81355 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/shader.h @@ -0,0 +1,126 @@ +#ifndef __ASURA_ENGINE_SHADER_H__ +#define __ASURA_ENGINE_SHADER_H__ + +#include <map> +#include <string> + +#include <asura-lib-utils/scripting/portable.hpp> +#include <asura-lib-utils/io/reloadable.h> +#include <asura-lib-utils/math/vector2.hpp> +#include <asura-lib-utils/math/vector3.hpp> +#include <asura-lib-utils/math/vector4.h> +#include <asura-lib-utils/math/matrix44.h> +#include <asura-lib-utils/stringmap.hpp> +#include <asura-lib-utils/manager.hpp> + +#include "color.h" +#include "texture.h" +#include "gl.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + /// + /// һshaderһڲʼ乲ijShaderuniformsͶݣֻṩuniformsuseɫķ༭ + /// ÿshaderͨshaderҵuniforms¶frameworkmaterialá + /// + class Shader ASURA_FINAL + : public Scripting::Portable<Shader> + , public AEIO::Reloadable + { + public: + + Shader(); + + ~Shader(); + + /// + /// ӴshaderʱȼǷϴλuniforms location mapʹglAttachShader±ɫ + /// ɫ + /// + bool Load(const std::string& vertexShader, const std::string& fragmentShader); + + /// + /// shaderΪ + /// + void Use(); + + /// + /// shaderΪǻ + /// + void Unuse(); + + /// + /// Ѿ֪uniform location£ֵ + /// + void SetUniformFloat(uint loc, float value); + void SetUniformTexture(uint loc, const Texture& texture); + void SetUniformVector2(uint loc, const Math::Vector2f& vec2); + void SetUniformVector3(uint loc, const Math::Vector3f& vec3); + void SetUniformVector4(uint loc, const Math::Vector4f& vec4); + void SetUniformColor(uint loc, const Color& color); + void SetUniformMatrix44(uint loc, const Math::Matrix44& mat44); + + uint GetUniformLocation(const std::string& uniform); + + bool HasUniform(const std::string& uniform); + + GLuint GetGLProgramHandle(); + + /// + /// texture unitһΪ16 + /// + static uint GetGLTextureUnitCount(); + + private: + + /// + /// ǰshader + /// + static Shader* mCurrentShader; + + /// + /// ñ + /// vec2 Asura_Time xֵΪ뵱ǰʼʱ䣬yֵΪһ֡ʱ + /// vec2 Asura_RenderTargetSize RTĴСΪλ + /// Texture Asura_MainTexture + /// + void SetBuiltInUniforms(); + + /// + /// OpenGL shader program handle. + /// + GLuint mProgramHandle; + + //------------------------------------------------------------------------------// + + public: + + LUAX_DECL_FACTORY(SimShader); + + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_Use); + LUAX_DECL_METHOD(_Unuse); + LUAX_DECL_METHOD(_Load); + LUAX_DECL_METHOD(_HasUniform); + LUAX_DECL_METHOD(_GetUniformLocation); + LUAX_DECL_METHOD(_SetBuiltInUniforms); + LUAX_DECL_METHOD(_SetUniformFloat); + LUAX_DECL_METHOD(_SetUniformTexture); + LUAX_DECL_METHOD(_SetUniformVector2); + LUAX_DECL_METHOD(_SetUniformVector3); + LUAX_DECL_METHOD(_SetUniformVector4); + LUAX_DECL_METHOD(_SetUniformColor); + + private: + + Luax::LuaxMemberRef mCodeLuaRef; + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/graphics/shape.cpp b/source/libs/asura-lib-core/graphics/shape.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/shape.cpp diff --git a/source/libs/asura-lib-core/graphics/shape.h b/source/libs/asura-lib-core/graphics/shape.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/shape.h diff --git a/source/libs/asura-lib-core/graphics/sprite_batch.cpp b/source/libs/asura-lib-core/graphics/sprite_batch.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/sprite_batch.cpp diff --git a/source/libs/asura-lib-core/graphics/sprite_batch.h b/source/libs/asura-lib-core/graphics/sprite_batch.h new file mode 100644 index 0000000..d8d9ca6 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/sprite_batch.h @@ -0,0 +1,28 @@ +#ifndef __ASURA_ENGINE_SPRITE_BATCH_H__ +#define __ASURA_ENGINE_SPRITE_BATCH_H__ + +#include <asura-lib-utils/scripting/portable.hpp> + +namespace AsuraEngine +{ + namespace Graphics + { + + /// + /// Sprite batchȾͼƬĵطϵͳ + /// + class SpriteBatch ASURA_FINAL + : public Scripting::Portable<SpriteBatch> + { + public: + + SpriteBatch(); + + ~SpriteBatch(); + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/graphics/stb_decoder.cpp b/source/libs/asura-lib-core/graphics/stb_decoder.cpp new file mode 100644 index 0000000..a13d6b8 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/stb_decoder.cpp @@ -0,0 +1,65 @@ +#include <asura-lib-utils/exceptions/exception.h> + +#include "stb_decoder.h" +#include "stb/stb_image.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + bool STBDecoder::CanDecode(const Filesystem::DataBuffer& buffer) + { + int w = 0; + int h = 0; + int comp = 0; + + int status = stbi_info_from_memory((const stbi_uc*)buffer.data, buffer.size, &w, &h, &comp); + + return status == 1 && w > 0 && h > 0; + } + + void STBDecoder::Decode(const Filesystem::DataBuffer& db, ImageData& imageData) + { + const stbi_uc *buffer = (const stbi_uc *)db.data; + int bufferlen = db.size; + int width, height; + int comp = 0; + byte* data = nullptr; + PixelFormat format = PIXELFORMAT_UNKNOWN; + std::size_t size = 0; + + if (stbi_is_hdr_from_memory(buffer, bufferlen)) + { + // 4channelfloat + data = (byte*)stbi_loadf_from_memory(buffer, bufferlen, &width, &height, &comp, STBI_rgb_alpha); + format = PIXELFORMAT_RGBA32F; + size = width * height * 4 * sizeof(float); + } + else + { + data = (byte*)stbi_load_from_memory(buffer, bufferlen, &width, &height, &comp, STBI_rgb_alpha); + format = PIXELFORMAT_ASTC_8x5; + size = width * height * 4; + } + if (data) + { + // ֤ڴ汻ͷţһϲûͷŵΪimage dataһԵģimageǶεġ + if (imageData.pixels) + delete[] imageData.pixels; + imageData.pixels = (byte*)data; + imageData.format = format; + imageData.width = width; + imageData.height = height; + } + else + { + const char *err = stbi_failure_reason(); + if (err == nullptr) + err = "unknown error"; + throw Exception("Could not decode image with stb_image (%s).", err); + } + } + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-core/graphics/stb_decoder.h b/source/libs/asura-lib-core/graphics/stb_decoder.h new file mode 100644 index 0000000..85bad21 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/stb_decoder.h @@ -0,0 +1,28 @@ +#ifndef __ASURA_ENGINE_STBDECODER_H__ +#define __ASURA_ENGINE_STBDECODER_H__ + +#include "image_decoder.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + /// + /// ʹstb_imageѹJPEGTGABMPļ + /// + class STBDecoder ASURA_FINAL + : public ImageDecoder + { + public: + + bool CanDecode(const AEIO::DataBuffer& buffer) override; + + void Decode(const AEIO::DataBuffer& buffer, ImageData& data) override; + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/graphics/texture.cpp b/source/libs/asura-lib-core/graphics/texture.cpp new file mode 100644 index 0000000..6cb6497 --- /dev/null +++ b/source/libs/asura-lib-core/graphics/texture.cpp @@ -0,0 +1,26 @@ +#include "Texture.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + Texture::Texture() + : mTextureHandle(0) + { + // GL texture + glGenTextures(1, &mTextureHandle); + } + + Texture::~Texture() + { + glDeleteTextures(1, &mTextureHandle); + } + + GLuint Texture::GetGLTextureHandle() const + { + return mTextureHandle; + } + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-core/graphics/texture.h b/source/libs/asura-lib-core/graphics/texture.h new file mode 100644 index 0000000..c412b2e --- /dev/null +++ b/source/libs/asura-lib-core/graphics/texture.h @@ -0,0 +1,68 @@ +#ifndef __ASURA_ENGINE_TEXTURE_H__ +#define __ASURA_ENGINE_TEXTURE_H__ + +#include <asura-lib-utils/math/rect.hpp> +#include <asura-lib-utils/math/vector2.hpp> +#include <asura-lib-utils/scripting/portable.hpp> + +#include "../core_config.h" + +#include "render_state.h" +#include "gl.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + class RenderTarget; + + /// + /// 2D࣬2d meshrender targetбʹáTextureȾԭϽǣϷϲԵѿϵΪ + /// EditorҲϽΪԭ㣬Ϊ˷㡣 + /// + ASURA_ABSTRACT class Texture + { + public: + + Texture(); + + virtual ~Texture(); + + GLuint GetGLTextureHandle() const; + + /// + /// ȾtexturertϣԭϽǣң + /// + virtual void Render(const RenderTarget* rt, const RenderState& state) = 0; + + /// + /// ȾtextureһֵrtϣԭϽǣң졣 + /// + virtual void Render(const RenderTarget* rt, const Math::Rectf& quad, const RenderState& state) = 0; + + /// + /// ù˷ʽ + /// + void SetSmooth(bool smooth); + + /// + /// ظʽ + /// + void SetRepeated(); + + protected: + + /// + /// OpenGL texture handle + /// + GLuint mTextureHandle; + + }; + + using Drawable = Texture; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/input/clipboard.cpp b/source/libs/asura-lib-core/input/clipboard.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/input/clipboard.cpp diff --git a/source/libs/asura-lib-core/input/clipboard.h b/source/libs/asura-lib-core/input/clipboard.h new file mode 100644 index 0000000..4cecd55 --- /dev/null +++ b/source/libs/asura-lib-core/input/clipboard.h @@ -0,0 +1,37 @@ +#ifndef __ASURA_ENGINE_CLIPBOARD_H__ +#define __ASURA_ENGINE_CLIPBOARD_H__ + +#include "Text/String.hpp" +#include "InputDevice.hpp" + +namespace AsuraEngine +{ + namespace Input + { + + class Clipboard ASURA_FINAL : public InputDevice<Clipboard> + { + public: + + Clipboard(); + + Text::String GetString(); + + void SetString(const Text::String& text); + + //---------------------------------------------------------------------------------------------------------- + + LUAX_DECL_SINGLETON(Clipboard); + + //---------------------------------------------------------------------------------------------------------- + + private: + + ~Clipboard(); + + }; + + }; +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/input/cursor.cpp b/source/libs/asura-lib-core/input/cursor.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/input/cursor.cpp diff --git a/source/libs/asura-lib-core/input/cursor.defs b/source/libs/asura-lib-core/input/cursor.defs new file mode 100644 index 0000000..f8b8492 --- /dev/null +++ b/source/libs/asura-lib-core/input/cursor.defs @@ -0,0 +1,25 @@ + +// Types of system cursors. +enum SystemCursor +{ + CURSOR_ARROW, + CURSOR_IBEAM, + CURSOR_WAIT, + CURSOR_CROSSHAIR, + CURSOR_WAITARROW, + CURSOR_SIZENWSE, + CURSOR_SIZENESW, + CURSOR_SIZEWE, + CURSOR_SIZENS, + CURSOR_SIZEALL, + CURSOR_NO, + CURSOR_HAND, + CURSOR_MAX_ENUM +}; + +enum CursorType +{ + CURSORTYPE_SYSTEM, + CURSORTYPE_IMAGE, + CURSORTYPE_MAX_ENUM +}; diff --git a/source/libs/asura-lib-core/input/cursor.h b/source/libs/asura-lib-core/input/cursor.h new file mode 100644 index 0000000..553fda4 --- /dev/null +++ b/source/libs/asura-lib-core/input/cursor.h @@ -0,0 +1,54 @@ +#ifndef __ASURA_ENGINE_CURSOR_H__ +#define __ASURA_ENGINE_CURSOR_H__ + +#include <SDL2/SDL.h> + +#include <asura-lib-utils/scripting/portable.hpp> + +#include "../graphics/image_data.h" + +#include "input_device.hpp" + +namespace AsuraEngine +{ + namespace Input + { + + class CursorImpl; + + // ָö +#include "Cursor.defs" + + class Cursor + : public AEScripting::Portable<Cursor> + { + public: + + LUAX_DECL_FACTORY(Cursor); + + Cursor(Graphics::ImageData& imageData, int hotx, int hoty); + Cursor(SystemCursor cursortype); + + ~Cursor(); + + SDL_Cursor* GetHandle() const; + CursorType GetType() const; + SystemCursor GetSystemType() const; + + private: + + CursorType mType; + SystemCursor mSystemType; + CursorImpl* mImpl; + + }; + + ASURA_ABSTRACT class CursorImpl + { + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/input/cursor_impl_sdl.cpp b/source/libs/asura-lib-core/input/cursor_impl_sdl.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/input/cursor_impl_sdl.cpp diff --git a/source/libs/asura-lib-core/input/cursor_impl_sdl.h b/source/libs/asura-lib-core/input/cursor_impl_sdl.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/input/cursor_impl_sdl.h diff --git a/source/libs/asura-lib-core/input/event.h b/source/libs/asura-lib-core/input/event.h new file mode 100644 index 0000000..a24e806 --- /dev/null +++ b/source/libs/asura-lib-core/input/event.h @@ -0,0 +1,45 @@ +#ifndef __ASURA_ENGINE_EVENT_H__ +#define __ASURA_ENGINE_EVENT_H__ + +namespace AsuraEngine +{ + namespace Input + { + + enum EventType + { + EVENT_BEGIN_MOUSE__ , + EVENT_LEFT_DOWN , + EVENT_LEFT_UP , + EVENT_LEFT_DCLICK , + EVENT_MIDDLE_DOWN , + EVENT_MIDDLE_UP , + EVENT_MIDDLE_DCLICK , + EVENT_RIGHT_DOWN , + EVENT_RIGHT_UP , + EVENT_RIGHT_DCLICK , + EVENT_MOTION , + EVENT_END_MOUSE__ , + EVENT_ENTER_WINDOW , + EVENT_LEAVE_WINDOW , + EVENT_MOUSEWHEEL + }; + + struct Event + { + int type; + union + { + // 갴¼ + struct { + int id; + } button; + }; + }; + + } +} + +namespace AEInput = AsuraEngine::Input; + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/input/input_device.hpp b/source/libs/asura-lib-core/input/input_device.hpp new file mode 100644 index 0000000..46f5be8 --- /dev/null +++ b/source/libs/asura-lib-core/input/input_device.hpp @@ -0,0 +1,31 @@ +#ifndef __ASURA_ENGINE_INPUT_BASE_H__ +#define __ASURA_ENGINE_INPUT_BASE_H__ + +#include <asura-lib-utils/scripting/portable.hpp> + +#include "../core_config.h" +#include "../singleton.hpp" + +namespace AsuraEngine +{ + namespace Input + { + + /// + /// 豸һ + /// + template<class T> + ASURA_ABSTRACT class InputDevice + : virtual public Scripting::Portable<T> + , virtual public Singleton<T> + { + public: + InputDevice(); + virtual ~InputDevice(); + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/input/joypad.h b/source/libs/asura-lib-core/input/joypad.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/input/joypad.h diff --git a/source/libs/asura-lib-core/input/keyboard.cpp b/source/libs/asura-lib-core/input/keyboard.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/input/keyboard.cpp diff --git a/source/libs/asura-lib-core/input/keyboard.defs b/source/libs/asura-lib-core/input/keyboard.defs new file mode 100644 index 0000000..8f04dc2 --- /dev/null +++ b/source/libs/asura-lib-core/input/keyboard.defs @@ -0,0 +1,482 @@ + +/** +* Keyboard keys. They are dependent on the current layout of the keyboard. +**/ +enum Key +{ + KEY_UNKNOWN, + + KEY_RETURN, + KEY_ESCAPE, + KEY_BACKSPACE, + KEY_TAB, + KEY_SPACE, + KEY_EXCLAIM, + KEY_QUOTEDBL, + KEY_HASH, + KEY_PERCENT, + KEY_DOLLAR, + KEY_AMPERSAND, + KEY_QUOTE, + KEY_LEFTPAREN, + KEY_RIGHTPAREN, + KEY_ASTERISK, + KEY_PLUS, + KEY_COMMA, + KEY_MINUS, + KEY_PERIOD, + KEY_SLASH, + KEY_0, + KEY_1, + KEY_2, + KEY_3, + KEY_4, + KEY_5, + KEY_6, + KEY_7, + KEY_8, + KEY_9, + KEY_COLON, + KEY_SEMICOLON, + KEY_LESS, + KEY_EQUALS, + KEY_GREATER, + KEY_QUESTION, + KEY_AT, + + KEY_LEFTBRACKET, + KEY_BACKSLASH, + KEY_RIGHTBRACKET, + KEY_CARET, + KEY_UNDERSCORE, + KEY_BACKQUOTE, + KEY_A, + KEY_B, + KEY_C, + KEY_D, + KEY_E, + KEY_F, + KEY_G, + KEY_H, + KEY_I, + KEY_J, + KEY_K, + KEY_L, + KEY_M, + KEY_N, + KEY_O, + KEY_P, + KEY_Q, + KEY_R, + KEY_S, + KEY_T, + KEY_U, + KEY_V, + KEY_W, + KEY_X, + KEY_Y, + KEY_Z, + + KEY_CAPSLOCK, + + KEY_F1, + KEY_F2, + KEY_F3, + KEY_F4, + KEY_F5, + KEY_F6, + KEY_F7, + KEY_F8, + KEY_F9, + KEY_F10, + KEY_F11, + KEY_F12, + + KEY_PRINTSCREEN, + KEY_SCROLLLOCK, + KEY_PAUSE, + KEY_INSERT, + KEY_HOME, + KEY_PAGEUP, + KEY_DELETE, + KEY_END, + KEY_PAGEDOWN, + KEY_RIGHT, + KEY_LEFT, + KEY_DOWN, + KEY_UP, + + KEY_NUMLOCKCLEAR, + KEY_KP_DIVIDE, + KEY_KP_MULTIPLY, + KEY_KP_MINUS, + KEY_KP_PLUS, + KEY_KP_ENTER, + KEY_KP_1, + KEY_KP_2, + KEY_KP_3, + KEY_KP_4, + KEY_KP_5, + KEY_KP_6, + KEY_KP_7, + KEY_KP_8, + KEY_KP_9, + KEY_KP_0, + KEY_KP_PERIOD, + KEY_KP_COMMA, + KEY_KP_EQUALS, + + KEY_APPLICATION, + KEY_POWER, + KEY_F13, + KEY_F14, + KEY_F15, + KEY_F16, + KEY_F17, + KEY_F18, + KEY_F19, + KEY_F20, + KEY_F21, + KEY_F22, + KEY_F23, + KEY_F24, + KEY_EXECUTE, + KEY_HELP, + KEY_MENU, + KEY_SELECT, + KEY_STOP, + KEY_AGAIN, + KEY_UNDO, + KEY_CUT, + KEY_COPY, + KEY_PASTE, + KEY_FIND, + KEY_MUTE, + KEY_VOLUMEUP, + KEY_VOLUMEDOWN, + + KEY_ALTERASE, + KEY_SYSREQ, + KEY_CANCEL, + KEY_CLEAR, + KEY_PRIOR, + KEY_RETURN2, + KEY_SEPARATOR, + KEY_OUT, + KEY_OPER, + KEY_CLEARAGAIN, + + KEY_THOUSANDSSEPARATOR, + KEY_DECIMALSEPARATOR, + KEY_CURRENCYUNIT, + KEY_CURRENCYSUBUNIT, + + KEY_LCTRL, + KEY_LSHIFT, + KEY_LALT, + KEY_LGUI, + KEY_RCTRL, + KEY_RSHIFT, + KEY_RALT, + KEY_RGUI, + + KEY_MODE, + + KEY_AUDIONEXT, + KEY_AUDIOPREV, + KEY_AUDIOSTOP, + KEY_AUDIOPLAY, + KEY_AUDIOMUTE, + KEY_MEDIASELECT, + KEY_WWW, + KEY_MAIL, + KEY_CALCULATOR, + KEY_COMPUTER, + KEY_APP_SEARCH, + KEY_APP_HOME, + KEY_APP_BACK, + KEY_APP_FORWARD, + KEY_APP_STOP, + KEY_APP_REFRESH, + KEY_APP_BOOKMARKS, + + KEY_BRIGHTNESSDOWN, + KEY_BRIGHTNESSUP, + KEY_DISPLAYSWITCH, + KEY_KBDILLUMTOGGLE, + KEY_KBDILLUMDOWN, + KEY_KBDILLUMUP, + KEY_EJECT, + KEY_SLEEP, + + KEY_MAX_ENUM +}; + +/** +* Scancodes represent physical keys independent of the current layout. +* Their names may not match the names of the keys printed on the keyboard. +* Some of them are very esoteric... +**/ +enum Scancode +{ + SCANCODE_UNKNOWN, + + SCANCODE_A, + SCANCODE_B, + SCANCODE_C, + SCANCODE_D, + SCANCODE_E, + SCANCODE_F, + SCANCODE_G, + SCANCODE_H, + SCANCODE_I, + SCANCODE_J, + SCANCODE_K, + SCANCODE_L, + SCANCODE_M, + SCANCODE_N, + SCANCODE_O, + SCANCODE_P, + SCANCODE_Q, + SCANCODE_R, + SCANCODE_S, + SCANCODE_T, + SCANCODE_U, + SCANCODE_V, + SCANCODE_W, + SCANCODE_X, + SCANCODE_Y, + SCANCODE_Z, + + SCANCODE_1, + SCANCODE_2, + SCANCODE_3, + SCANCODE_4, + SCANCODE_5, + SCANCODE_6, + SCANCODE_7, + SCANCODE_8, + SCANCODE_9, + SCANCODE_0, + + SCANCODE_RETURN, + SCANCODE_ESCAPE, + SCANCODE_BACKSPACE, + SCANCODE_TAB, + SCANCODE_SPACE, + + SCANCODE_MINUS, + SCANCODE_EQUALS, + SCANCODE_LEFTBRACKET, + SCANCODE_RIGHTBRACKET, + SCANCODE_BACKSLASH, + SCANCODE_NONUSHASH, + SCANCODE_SEMICOLON, + SCANCODE_APOSTROPHE, + SCANCODE_GRAVE, + SCANCODE_COMMA, + SCANCODE_PERIOD, + SCANCODE_SLASH, + + SCANCODE_CAPSLOCK, + + SCANCODE_F1, + SCANCODE_F2, + SCANCODE_F3, + SCANCODE_F4, + SCANCODE_F5, + SCANCODE_F6, + SCANCODE_F7, + SCANCODE_F8, + SCANCODE_F9, + SCANCODE_F10, + SCANCODE_F11, + SCANCODE_F12, + + SCANCODE_PRINTSCREEN, + SCANCODE_SCROLLLOCK, + SCANCODE_PAUSE, + SCANCODE_INSERT, + SCANCODE_HOME, + SCANCODE_PAGEUP, + SCANCODE_DELETE, + SCANCODE_END, + SCANCODE_PAGEDOWN, + SCANCODE_RIGHT, + SCANCODE_LEFT, + SCANCODE_DOWN, + SCANCODE_UP, + + SCANCODE_NUMLOCKCLEAR, + SCANCODE_KP_DIVIDE, + SCANCODE_KP_MULTIPLY, + SCANCODE_KP_MINUS, + SCANCODE_KP_PLUS, + SCANCODE_KP_ENTER, + SCANCODE_KP_1, + SCANCODE_KP_2, + SCANCODE_KP_3, + SCANCODE_KP_4, + SCANCODE_KP_5, + SCANCODE_KP_6, + SCANCODE_KP_7, + SCANCODE_KP_8, + SCANCODE_KP_9, + SCANCODE_KP_0, + SCANCODE_KP_PERIOD, + + SCANCODE_NONUSBACKSLASH, + SCANCODE_APPLICATION, + SCANCODE_POWER, + SCANCODE_KP_EQUALS, + SCANCODE_F13, + SCANCODE_F14, + SCANCODE_F15, + SCANCODE_F16, + SCANCODE_F17, + SCANCODE_F18, + SCANCODE_F19, + SCANCODE_F20, + SCANCODE_F21, + SCANCODE_F22, + SCANCODE_F23, + SCANCODE_F24, + SCANCODE_EXECUTE, + SCANCODE_HELP, + SCANCODE_MENU, + SCANCODE_SELECT, + SCANCODE_STOP, + SCANCODE_AGAIN, + SCANCODE_UNDO, + SCANCODE_CUT, + SCANCODE_COPY, + SCANCODE_PASTE, + SCANCODE_FIND, + SCANCODE_MUTE, + SCANCODE_VOLUMEUP, + SCANCODE_VOLUMEDOWN, + SCANCODE_KP_COMMA, + SCANCODE_KP_EQUALSAS400, + + SCANCODE_INTERNATIONAL1, + SCANCODE_INTERNATIONAL2, + SCANCODE_INTERNATIONAL3, + SCANCODE_INTERNATIONAL4, + SCANCODE_INTERNATIONAL5, + SCANCODE_INTERNATIONAL6, + SCANCODE_INTERNATIONAL7, + SCANCODE_INTERNATIONAL8, + SCANCODE_INTERNATIONAL9, + SCANCODE_LANG1, + SCANCODE_LANG2, + SCANCODE_LANG3, + SCANCODE_LANG4, + SCANCODE_LANG5, + SCANCODE_LANG6, + SCANCODE_LANG7, + SCANCODE_LANG8, + SCANCODE_LANG9, + + SCANCODE_ALTERASE, + SCANCODE_SYSREQ, + SCANCODE_CANCEL, + SCANCODE_CLEAR, + SCANCODE_PRIOR, + SCANCODE_RETURN2, + SCANCODE_SEPARATOR, + SCANCODE_OUT, + SCANCODE_OPER, + SCANCODE_CLEARAGAIN, + SCANCODE_CRSEL, + SCANCODE_EXSEL, + + SCANCODE_KP_00, + SCANCODE_KP_000, + SCANCODE_THOUSANDSSEPARATOR, + SCANCODE_DECIMALSEPARATOR, + SCANCODE_CURRENCYUNIT, + SCANCODE_CURRENCYSUBUNIT, + SCANCODE_KP_LEFTPAREN, + SCANCODE_KP_RIGHTPAREN, + SCANCODE_KP_LEFTBRACE, + SCANCODE_KP_RIGHTBRACE, + SCANCODE_KP_TAB, + SCANCODE_KP_BACKSPACE, + SCANCODE_KP_A, + SCANCODE_KP_B, + SCANCODE_KP_C, + SCANCODE_KP_D, + SCANCODE_KP_E, + SCANCODE_KP_F, + SCANCODE_KP_XOR, + SCANCODE_KP_POWER, + SCANCODE_KP_PERCENT, + SCANCODE_KP_LESS, + SCANCODE_KP_GREATER, + SCANCODE_KP_AMPERSAND, + SCANCODE_KP_DBLAMPERSAND, + SCANCODE_KP_VERTICALBAR, + SCANCODE_KP_DBLVERTICALBAR, + SCANCODE_KP_COLON, + SCANCODE_KP_HASH, + SCANCODE_KP_SPACE, + SCANCODE_KP_AT, + SCANCODE_KP_EXCLAM, + SCANCODE_KP_MEMSTORE, + SCANCODE_KP_MEMRECALL, + SCANCODE_KP_MEMCLEAR, + SCANCODE_KP_MEMADD, + SCANCODE_KP_MEMSUBTRACT, + SCANCODE_KP_MEMMULTIPLY, + SCANCODE_KP_MEMDIVIDE, + SCANCODE_KP_PLUSMINUS, + SCANCODE_KP_CLEAR, + SCANCODE_KP_CLEARENTRY, + SCANCODE_KP_BINARY, + SCANCODE_KP_OCTAL, + SCANCODE_KP_DECIMAL, + SCANCODE_KP_HEXADECIMAL, + + SCANCODE_LCTRL, + SCANCODE_LSHIFT, + SCANCODE_LALT, + SCANCODE_LGUI, + SCANCODE_RCTRL, + SCANCODE_RSHIFT, + SCANCODE_RALT, + SCANCODE_RGUI, + + SCANCODE_MODE, + + SCANCODE_AUDIONEXT, + SCANCODE_AUDIOPREV, + SCANCODE_AUDIOSTOP, + SCANCODE_AUDIOPLAY, + SCANCODE_AUDIOMUTE, + SCANCODE_MEDIASELECT, + SCANCODE_WWW, + SCANCODE_MAIL, + SCANCODE_CALCULATOR, + SCANCODE_COMPUTER, + SCANCODE_AC_SEARCH, + SCANCODE_AC_HOME, + SCANCODE_AC_BACK, + SCANCODE_AC_FORWARD, + SCANCODE_AC_STOP, + SCANCODE_AC_REFRESH, + SCANCODE_AC_BOOKMARKS, + + SCANCODE_BRIGHTNESSDOWN, + SCANCODE_BRIGHTNESSUP, + SCANCODE_DISPLAYSWITCH, + SCANCODE_KBDILLUMTOGGLE, + SCANCODE_KBDILLUMDOWN, + SCANCODE_KBDILLUMUP, + SCANCODE_EJECT, + SCANCODE_SLEEP, + + SCANCODE_APP1, + SCANCODE_APP2, + + SCANCODE_MAX_ENUM +}; diff --git a/source/libs/asura-lib-core/input/keyboard.h b/source/libs/asura-lib-core/input/keyboard.h new file mode 100644 index 0000000..1480d06 --- /dev/null +++ b/source/libs/asura-lib-core/input/keyboard.h @@ -0,0 +1,73 @@ +//#ifndef __ASURA_INPUT_KEYBOARD_H__ +//#define __ASURA_INPUT_KEYBOARD_H__ +// +//#include <SDL2/SDL.h> +// +//#include "InputDevice.hpp" +//#include "Scripting/Portable.h" +// +//namespace AsuraEngine +//{ +// namespace Input +// { +// +// class Keyboard ASURA_FINAL : public InputDevice<Keyboard> +// { +// public: +// +// // صö +// #include "Keyboard.defs" +// +// Keyboard(); +// +// void SetKeyRepeat(bool enable); +// bool HasKeyRepeat() const; +// bool IsDown(const std::vector<Key> &keylist) const; +// bool IsScancodeDown(const std::vector<Scancode> &scancodelist) const; +// +// Key GetKeyFromScancode(Scancode scancode) const; +// Scancode GetScancodeFromKey(Key key) const; +// +// void SetTextInput(bool enable); +// void SetTextInput(bool enable, double x, double y, double w, double h); +// bool HasTextInput() const; +// bool HasScreenKeyboard() const; +// +// bool GetConstant(Scancode in, SDL_Scancode &out); +// bool GetConstant(SDL_Scancode in, Scancode &out); +// +// private: +// +// ~Keyboard(); +// +// public: +// +// //---------------------------------------------------------------------------------------------------------- +// +// LUAX_DECL_SINGLETON(Keyboard); // ͨAsuraEngine.KeyboardֱӷʣûNew +// +// LUAX_DECL_ENUM(Key); +// LUAX_DECL_ENUM(ScanCode); +// +// LUAX_DECL_METHOD(SetKeyRepeat); +// LUAX_DECL_METHOD(HasKeyRepeat); +// LUAX_DECL_METHOD(IsDown); +// LUAX_DECL_METHOD(IsScancodeDown); +// +// LUAX_DECL_METHOD(GetKeyFromScancode); +// LUAX_DECL_METHOD(GetScancodeFromKey); +// +// LUAX_DECL_METHOD(SetTextInput); +// LUAX_DECL_METHOD(HasTextInput); +// LUAX_DECL_METHOD(HasScreenKeyboard); +// +// LUAX_DECL_METHOD(GetConstant); +// +// //---------------------------------------------------------------------------------------------------------- +// +// }; +// +// } +//} +// +//#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/input/mouse.cpp b/source/libs/asura-lib-core/input/mouse.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/input/mouse.cpp diff --git a/source/libs/asura-lib-core/input/mouse.defs b/source/libs/asura-lib-core/input/mouse.defs new file mode 100644 index 0000000..de1d117 --- /dev/null +++ b/source/libs/asura-lib-core/input/mouse.defs @@ -0,0 +1,7 @@ + +enum MouseButton +{ + MOUSE_BUTTON_LEFT, + MOUSE_BUTTON_MIDDLE, + MOUSE_BUTTON_RIGHT, +}; diff --git a/source/libs/asura-lib-core/input/mouse.h b/source/libs/asura-lib-core/input/mouse.h new file mode 100644 index 0000000..3ab67fa --- /dev/null +++ b/source/libs/asura-lib-core/input/mouse.h @@ -0,0 +1,56 @@ +#ifndef __ASURA_ENGINE_MOUSE_H__ +#define __ASURA_ENGINE_MOUSE_H__ + +#include "cursor.h" +#include "input_device.hpp" + +namespace AsuraEngine +{ + namespace Input + { + + class Mouse : public InputDevice<Mouse> + { + public: + + /// + /// ͼƬйָʹϵͳָ + /// + Cursor *CreateCursor(Graphics::ImageData *data, int hotx, int hoty); + Cursor *GetSystemCursor(Cursor::SystemCursor cursortype); + + void SetCursor(Cursor *cursor); + void SetCursor() ; + + Cursor* GetCursor() const; + + bool IsCursorSupported() const; + + double GetX() const; + double GetY() const; + void GetPosition(double &x, double &y) const; + void GetX(double x) ; + void SetY(double y) ; + void SetPosition(double x, double y) ; + void SetVisible(bool visible) ; + bool IsDown(const std::vector<int> &buttons) const; + bool IsVisible() const; + void SetGrabbed(bool grab) ; + bool IsGrabbed() const; + bool SetRelativeMode(bool relative) ; + bool GetRelativeMode() const; + + //---------------------------------------------------------------------------------------------------------- + + LUAX_DECL_SINGLETON(Mouse); + + //---------------------------------------------------------------------------------------------------------- + + private: + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/profiler/stats.cpp b/source/libs/asura-lib-core/profiler/stats.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/profiler/stats.cpp diff --git a/source/libs/asura-lib-core/profiler/stats.h b/source/libs/asura-lib-core/profiler/stats.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/profiler/stats.h diff --git a/source/libs/asura-lib-core/threading/coroutine.cpp b/source/libs/asura-lib-core/threading/coroutine.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/threading/coroutine.cpp diff --git a/source/libs/asura-lib-core/threading/coroutine.h b/source/libs/asura-lib-core/threading/coroutine.h new file mode 100644 index 0000000..1ac6b21 --- /dev/null +++ b/source/libs/asura-lib-core/threading/coroutine.h @@ -0,0 +1,31 @@ +#ifndef __ASURA_COROUTINE_H__ +#define __ASURA_COROUTINE_H__ + +#include <asura-lib-utils/scripting/portable.hpp> + +namespace AsuraEngine +{ + namespace Threading + { + + /// + /// luaЭ̣һЩ + /// + class Coroutine ASURA_FINAL + : public AEScripting::Portable<Coroutine> + { + public: + + LUAX_DECL_FACTORY(Coroutine); + + private: + + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_Run); + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/threading/thread.cpp b/source/libs/asura-lib-core/threading/thread.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/threading/thread.cpp diff --git a/source/libs/asura-lib-core/threading/thread.h b/source/libs/asura-lib-core/threading/thread.h new file mode 100644 index 0000000..f4d3b48 --- /dev/null +++ b/source/libs/asura-lib-core/threading/thread.h @@ -0,0 +1,53 @@ +#ifndef __ASURA_THREAD_H__ +#define __ASURA_THREAD_H__ + +#include <queue> +#include <asura-lib-utils/scripting/portable.hpp> + +#include "thread_task.h" + +namespace AsuraEngine +{ + namespace Threading + { + + /// + /// ̵߳ľʵ֣ûģһֲԣ + /// 1: win32 + /// 2: posix + /// 3: SDL + /// 4: std::thread + /// + ASURA_ABSTRACT class ThreadImpl + { + public: + + }; + + /// + /// ߳壬ÿ߳άһtask queue + /// + class Thread ASURA_FINAL + : public AEScripting::Portable<Thread> + { + public: + + LUAX_DECL_FACTORY(Thread); + + bool Enqueue(ThreadTask* task); + + private: + + /// + /// С + /// + std::queue<ThreadTask*> mTaskQueue; + + ThreadImpl* mImpl; + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/threading/thread_impl_posix.cpp b/source/libs/asura-lib-core/threading/thread_impl_posix.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/threading/thread_impl_posix.cpp diff --git a/source/libs/asura-lib-core/threading/thread_impl_posix.h b/source/libs/asura-lib-core/threading/thread_impl_posix.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/threading/thread_impl_posix.h diff --git a/source/libs/asura-lib-core/threading/thread_impl_sdl.cpp b/source/libs/asura-lib-core/threading/thread_impl_sdl.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/threading/thread_impl_sdl.cpp diff --git a/source/libs/asura-lib-core/threading/thread_impl_sdl.h b/source/libs/asura-lib-core/threading/thread_impl_sdl.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/threading/thread_impl_sdl.h diff --git a/source/libs/asura-lib-core/threading/thread_impl_std.cpp b/source/libs/asura-lib-core/threading/thread_impl_std.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/threading/thread_impl_std.cpp diff --git a/source/libs/asura-lib-core/threading/thread_impl_std.h b/source/libs/asura-lib-core/threading/thread_impl_std.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/threading/thread_impl_std.h diff --git a/source/libs/asura-lib-core/threading/thread_impl_win32.cpp b/source/libs/asura-lib-core/threading/thread_impl_win32.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/threading/thread_impl_win32.cpp diff --git a/source/libs/asura-lib-core/threading/thread_impl_win32.h b/source/libs/asura-lib-core/threading/thread_impl_win32.h new file mode 100644 index 0000000..5d854cc --- /dev/null +++ b/source/libs/asura-lib-core/threading/thread_impl_win32.h @@ -0,0 +1,25 @@ +#ifndef __ASURA_THREAD_WIN32_H__ +#define __ASURA_THREAD_WIN32_H__ + +#include "../core_config.h" + +#include "thread.h" + +#if ASURA_THREAD_WIN32 + +namespace AsuraEngine +{ + namespace Threading + { + + class ThreadImplWin32 : public ThreadImpl + { + + }; + + } +} + +#endif // #if ASURA_THREAD_WIN32 + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/threading/thread_task.cpp b/source/libs/asura-lib-core/threading/thread_task.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/threading/thread_task.cpp diff --git a/source/libs/asura-lib-core/threading/thread_task.h b/source/libs/asura-lib-core/threading/thread_task.h new file mode 100644 index 0000000..19eb113 --- /dev/null +++ b/source/libs/asura-lib-core/threading/thread_task.h @@ -0,0 +1,25 @@ +#ifndef __ASURA_THRAD_TASK_H__ +#define __ASURA_THRAD_TASK_H__ + +#include <asura-lib-utils/type.h> + +namespace AsuraEngine +{ + namespace Threading + { + + /// + /// ϣһ̴̳߳TaskдExecute + /// + ASURA_ABSTRACT class ThreadTask + { + public: + + virtual bool Execute() = 0; + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/time/timer.cpp b/source/libs/asura-lib-core/time/timer.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/time/timer.cpp diff --git a/source/libs/asura-lib-core/time/timer.h b/source/libs/asura-lib-core/time/timer.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/time/timer.h diff --git a/source/libs/asura-lib-core/type.h b/source/libs/asura-lib-core/type.h new file mode 100644 index 0000000..88848d5 --- /dev/null +++ b/source/libs/asura-lib-core/type.h @@ -0,0 +1,11 @@ +#ifndef __ASURA_ENGINE_TYPE_H__ +#define __ASURA_ENGINE_TYPE_H__ + +#include <stdint.h> + +namespace AsuraEngine +{ + +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/window/window.cpp b/source/libs/asura-lib-core/window/window.cpp new file mode 100644 index 0000000..83a4f53 --- /dev/null +++ b/source/libs/asura-lib-core/window/window.cpp @@ -0,0 +1,50 @@ +#include "Config.h" +#include "Window.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + Window::Window(WindowStyle style) + { + } + + Window::~Window() + { + + } + + void Window::SetPosition(int x, int y) + { + ASSERT(mWindowHandle); + SDL_SetWindowPosition(mWindowHandle, x, y); + } + + void Window::SetTitle(const std::string& title) + { + + } + + void Window::Show() + { + + } + + void Window::Hide() + { + + } + + void Window::SetWindowStyle(WindowStyle style) + { + + } + + void Window::SwapRenderBuffer() + { + + } + + } +} diff --git a/source/libs/asura-lib-core/window/window.h b/source/libs/asura-lib-core/window/window.h new file mode 100644 index 0000000..39db73e --- /dev/null +++ b/source/libs/asura-lib-core/window/window.h @@ -0,0 +1,90 @@ +#ifndef __ASURA_ENGINE_WINDOW_H__ +#define __ASURA_ENGINE_WINDOW_H__ + +#include <asura-lib-utils/scripting/portable.hpp> +#include <asura-lib-utils/math/vector2.hpp> + +#include "../graphics/render_state.h" +#include "../graphics/render_target.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + class WindowImpl; + + enum WindowStyle + { + WINDOW_STYLE_FULLSCREEN = 1 << 1, + }; + + /// + /// ϷĵڣrunnerֻҪһڡͬĿͻʵִ˽ӿڲֶעᵽlua༭ᵼ࣬ӵ༭ + /// ⴰϡ + /// + class Window + : public RenderTarget + , public AEScripting::Portable<Window> + { + public: + + LUAX_DECL_SINGLETON(Window); + + Window(WindowStyle style); + + ~Window(); + + void SetSize(uint width, uint height); + + void SetPosition(int x, int y); + + void SetTitle(const std::string& title); + + void SetWindowStyle(WindowStyle style); + + void Show(); + + void Hide(); + + /// + /// ǿ˫ĴڣҪչʾǰ̨ + /// + void SwapRenderBuffer(); + + void Clear(const Color& col = Color::Black); + + void Clear(const Math::Recti& quad, const Color& col = Color::Black); + + void Draw(const Drawable* texture, const RenderState& state); + + void Draw(const Drawable* texture, const Math::Recti& quad, const RenderState& state); + + protected: + + WindowImpl* mImpl; + + LUAX_DECL_METHOD(_Show); + LUAX_DECL_METHOD(_Hide); + LUAX_DECL_METHOD(_SetResolution); + LUAX_DECL_METHOD(_SetFullScreen); + LUAX_DECL_METHOD(_SetTitle); + LUAX_DECL_METHOD(_SetWindowStyle); + LUAX_DECL_METHOD(_Clear); + LUAX_DECL_METHOD(_Draw); + LUAX_DECL_METHOD(_SwapRenderBuffer); + + }; + + using RenderWindow = Window; + + ASURA_ABSTRACT class WindowImpl + { + public: + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-core/window/window_impl_glew.cpp b/source/libs/asura-lib-core/window/window_impl_glew.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/window/window_impl_glew.cpp diff --git a/source/libs/asura-lib-core/window/window_impl_glew.h b/source/libs/asura-lib-core/window/window_impl_glew.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/window/window_impl_glew.h diff --git a/source/libs/asura-lib-core/window/window_impl_glut.cpp b/source/libs/asura-lib-core/window/window_impl_glut.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/window/window_impl_glut.cpp diff --git a/source/libs/asura-lib-core/window/window_impl_glut.h b/source/libs/asura-lib-core/window/window_impl_glut.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/window/window_impl_glut.h diff --git a/source/libs/asura-lib-core/window/window_impl_sdl.cpp b/source/libs/asura-lib-core/window/window_impl_sdl.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/window/window_impl_sdl.cpp diff --git a/source/libs/asura-lib-core/window/window_impl_sdl.h b/source/libs/asura-lib-core/window/window_impl_sdl.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-core/window/window_impl_sdl.h diff --git a/source/libs/asura-lib-framework/compile.bat b/source/libs/asura-lib-framework/compile.bat new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-framework/compile.bat diff --git a/source/libs/asura-lib-framework/compile.sh b/source/libs/asura-lib-framework/compile.sh new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-framework/compile.sh diff --git a/source/libs/asura-lib-framework/main.cpp b/source/libs/asura-lib-framework/main.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-framework/main.cpp diff --git a/source/libs/asura-lib-framework/scripts/ai/behavior_tree.lua b/source/libs/asura-lib-framework/scripts/ai/behavior_tree.lua new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/ai/behavior_tree.lua diff --git a/source/libs/asura-lib-framework/scripts/ai/state_graph.lua b/source/libs/asura-lib-framework/scripts/ai/state_graph.lua new file mode 100644 index 0000000..4f563dc --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/ai/state_graph.lua @@ -0,0 +1,11 @@ +local StateGraph = AsuraEngine.Asset.Extend("StateGraph") + +AsuraEngine.StateGraph = StateGraph + +function StateGraph.Ctor(self) + +end + +function StateGraph.ToAsset() + +end
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/ai/state_machine.lua b/source/libs/asura-lib-framework/scripts/ai/state_machine.lua new file mode 100644 index 0000000..6dc5e14 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/ai/state_machine.lua @@ -0,0 +1,6 @@ +local StateMachine = Class() +AsuraEngine.StateMachine = StateMachine + +function StateMachine.Ctor(self, stategraph) + self.stategraph = stategraph +end
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/audio/sound.lua b/source/libs/asura-lib-framework/scripts/audio/sound.lua new file mode 100644 index 0000000..d7dea4f --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/audio/sound.lua @@ -0,0 +1,9 @@ +AsuraEngine.Sound = AsuraEngine.Asset.Extend("Sound") + +local Sound = AsuraEngine.Sound + +function Sound.Ctor(self) + +end + +return Sound
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/audio/source.lua b/source/libs/asura-lib-framework/scripts/audio/source.lua new file mode 100644 index 0000000..7dec511 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/audio/source.lua @@ -0,0 +1,22 @@ +-- Audio Source +AsuraEngine.Source = AsuraEngine.Component.Extend("SoundPlayer") + +local Source = AsuraEngine.Source + +function Source.Ctor(self) + self.mSound = nil +end + +function Source.SetSound(sound) + self.mSound = sound +end + +function Source.GetSource() + return self.mSound +end + +function Source.OnUpdate(dt) + +end + +return Source
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/class.lua b/source/libs/asura-lib-framework/scripts/class.lua new file mode 100644 index 0000000..6392483 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/class.lua @@ -0,0 +1,17 @@ +AsuraEngine.Class = {} + +local Class = AsuraEngine.Class +Class.__index = Class + +function Class.Extend(base, classname) + local subclass = {} + base.__index = base + setmetatable(subclass, base) + return c +end + +function Class.New(cls) + local obj = {} + setmetatable(obj, cls) + cls.__index = cls +end
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/component.lua b/source/libs/asura-lib-framework/scripts/component.lua new file mode 100644 index 0000000..b560bd3 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/component.lua @@ -0,0 +1,30 @@ +AsuraEngine.Component = AsuraEngine.Class("Component") + +local Component = AsuraEngine.Component + +-- Component要显示在inspector的变量 +Component.entity = AsuraEngine.Type.Entity + +function Component.Extend(cname) + self.base(cname) + assert(Component.components[cname] == nil) + +end + +function Component:Ctor(entity) + self.entity = entity +end + +function Component:OnEvent(e) + +end + +function Component:OnUpdate(ms) + +end + +function Component:OnDraw() + +end + +return Component
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/entity.lua b/source/libs/asura-lib-framework/scripts/entity.lua new file mode 100644 index 0000000..ea8e14d --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/entity.lua @@ -0,0 +1,114 @@ +-- +-- 实体,作为scene中的实体存在。Scene中唯一管理的就是实体entity,游戏里的所有component都依附于entity存在,包括camera组件。 +-- +module "AsuraEngine" +require "transform" + +AsuraEngine.Entity = AsuraEngine.Asset.Extend("Entity") + +local Entity = AsuraEngine.Entity + +function Entity:Ctor() + self.transform = AsuraEngine.Transform.New() + self.subentities = {} -- Extend node entities +end + +function Entity:AddChild(entity) + table.insert(self.child, entity) +end + +function Entity:AddComponent(type, name) + local cname = type + if name == nil then + cname = name + end + local component = AsuraEngine.Component.GetComponent(type) + self.components[cname] = compoennt +end + +function Entity:GetComponent(name) + return self.components[name] +end + +function Entity:GetComponentByType(type) + +end + +function Entity:OnEnable() + +end + +function Entity:OnEvent(e) + if self.components == nil or type(self.components) ~= "table" then + AsuraEditor.LogError("") + return + end + for name, component in self.components do + if component.OnEvent ~= nil then + component:OnEvent(e) + end + end +end + +function Entity:OnUpdate(dt) + for name, component in self.components do + if component.OnUpdate ~= nil then + component:OnUpdate(dt) + end + end +end + +function Entity:OnRender() + for name, component in self.components do + if component.OnRender ~= nil then + component.OnRender() + end + end +end + +function Entity:OnDisable() + for name, component in self.components do + if component.OnDisable ~= nil then + component.OnDisable() + end + end +end + +function Entity:GetTrasform() + return self.transform +end + +function Entity:GetPosition() + +end + +function Entity:GetScale() + +end + +function Entity:GetRotation() + +end + +function Entity:SetTrasform(transform) + +end + +function Entity:SetPosition() + +end + +function Entity:SetScale() + +end + +function Entity:SetRotation() + +end + +--写asset +function Entity:ToAsset() + +end + +return Entity
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/filesystem/animation_loader.lua b/source/libs/asura-lib-framework/scripts/filesystem/animation_loader.lua new file mode 100644 index 0000000..9c57c43 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/filesystem/animation_loader.lua @@ -0,0 +1,10 @@ +require "AnimationManager" +require "Animation" + +local loader = AsuraEngine.Loader.New("animation") +local manager = AsuraEngine.AnimationManager +local Animation = AsuraEngine.Animation + +function AnimationLoader.OnLoad(asset) + local animation = AsuraEngine.Class() +end
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/filesystem/asset.lua b/source/libs/asura-lib-framework/scripts/filesystem/asset.lua new file mode 100644 index 0000000..7cf3905 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/filesystem/asset.lua @@ -0,0 +1,20 @@ +-- +-- 游戏资源类需要继承Asset类,引擎读取.asset文件寻找对应的loader加载进游戏生成对应的Asset派生类对象。对于脚本,不会 +-- 生成对应的对象,而是直接运行脚本将结果保存。 +-- +AsuraEngine.Asset = AsuraEngine.Class("Asset") + +local Asset = AsuraEngine.Asset + +function Asset.Ctor(self) + self.guid = nil +end + +--获得资源编号 +function Asset.GetGUID(self) + +end + +function Asset.GetAssetByGUID(guid) + +end
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/filesystem/entity_loader.lua b/source/libs/asura-lib-framework/scripts/filesystem/entity_loader.lua new file mode 100644 index 0000000..39ae0d9 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/filesystem/entity_loader.lua @@ -0,0 +1,5 @@ +local loader = AsuraEngine.Loader.New("entity") + +function loader.OnLoad(asset) + +end
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/filesystem/image_loader.lua b/source/libs/asura-lib-framework/scripts/filesystem/image_loader.lua new file mode 100644 index 0000000..6b0bef7 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/filesystem/image_loader.lua @@ -0,0 +1,13 @@ +require "graphics.image" +local loader = AsuraEngine.Loader.New("image") + +function loader.OnLoad(asset) + assert(asset ~= nil) + local path = asset.extern + local image = AusraEngine.Image.New(path) + if image == nil then + AsuraEngine.LogError("") + return + end + return image +end diff --git a/source/libs/asura-lib-framework/scripts/filesystem/loader.lua b/source/libs/asura-lib-framework/scripts/filesystem/loader.lua new file mode 100644 index 0000000..e192e30 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/filesystem/loader.lua @@ -0,0 +1,12 @@ +-- Assets loaders +AsuraEngine.Loader = {} +local Loader = AsuraEngine.Loader +Loader.Loaders = {} + +function Loader.New(type) + assert(Loader.Loaders[type] == nil) + local loader = {} + Loader[type] = loader + return loader +end + diff --git a/source/libs/asura-lib-framework/scripts/filesystem/material_loader.lua b/source/libs/asura-lib-framework/scripts/filesystem/material_loader.lua new file mode 100644 index 0000000..07ca4e9 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/filesystem/material_loader.lua @@ -0,0 +1,7 @@ +require "MaterialManager" + +local loader = AsuraEngine.Loader.New("material") + +function loader.OnLoad(asset) + +end
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/filesystem/path_loader.lua b/source/libs/asura-lib-framework/scripts/filesystem/path_loader.lua new file mode 100644 index 0000000..986e42c --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/filesystem/path_loader.lua @@ -0,0 +1,9 @@ +require "Path/PathManager" + +local loader = AsuraEngine.Loader.New("path") + +function loader.OnLoad(asset) + if asset.type ~= "path" then + return nil + end +end
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/filesystem/scene_loader.lua b/source/libs/asura-lib-framework/scripts/filesystem/scene_loader.lua new file mode 100644 index 0000000..45731f8 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/filesystem/scene_loader.lua @@ -0,0 +1,7 @@ +local Scene = require "scene" + +local loader = AsuraEngine.Loader.New("scene") + +function loader.OnLoad(asset) + +end
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/filesystem/script_loader.lua b/source/libs/asura-lib-framework/scripts/filesystem/script_loader.lua new file mode 100644 index 0000000..e93d903 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/filesystem/script_loader.lua @@ -0,0 +1,5 @@ +local loader = AsuraEngine.Loader.New("script") + +function loader.OnLoad(asset) + +end
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/filesystem/shader_loader.lua b/source/libs/asura-lib-framework/scripts/filesystem/shader_loader.lua new file mode 100644 index 0000000..12d88bb --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/filesystem/shader_loader.lua @@ -0,0 +1,5 @@ +local loader = AsuraEngine.Loader.New("shader") + +function loader.OnLoad(asset) + +end
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/filesystem/statemap_loader.lua b/source/libs/asura-lib-framework/scripts/filesystem/statemap_loader.lua new file mode 100644 index 0000000..e52e086 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/filesystem/statemap_loader.lua @@ -0,0 +1,7 @@ +require "ai/statemap_manager" +local loader = AsuraEngine.Loader.New("statemap") + +--载入statemap +function loader.OnLoad(asset) + +end
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/framework.lua b/source/libs/asura-lib-framework/scripts/framework.lua new file mode 100644 index 0000000..4643221 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/framework.lua @@ -0,0 +1,21 @@ +package.path = "scripts\\?.lua" + +--loader +local loadfn = function(modulename) + local errmsg = "" + local modulepath = string.gsub(modulename, "%.", "/") + for path in string.gmatch(package.path, "([^;]+)") do + local filename = string.gsub(path, "%?", modulepath) + filename = string.gsub(filename, "\\", "/") + local result = kleiloadlua(filename) + if result then + return result + end + errmsg = errmsg.."\n\tno file '"..filename.."' (checked with custom loader)" + end + return errmsg +end + +table.insert(package.loaders, 1, loadfn) + +require "" diff --git a/source/libs/asura-lib-framework/scripts/graphics/animation.lua b/source/libs/asura-lib-framework/scripts/graphics/animation.lua new file mode 100644 index 0000000..285adaa --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/graphics/animation.lua @@ -0,0 +1,15 @@ +AsuraEngine.Animation = AsuraEngine.Asset.Extend("Animation") + +local Animation = AsuraEngine.Animation + +local Frame = AsuraEngine.Class("Frame") + +function Frame.Ctor(self) + +end + +function Animation.Ctor(self) + +end + +return Animation
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/graphics/animator.lua b/source/libs/asura-lib-framework/scripts/graphics/animator.lua new file mode 100644 index 0000000..fd2f979 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/graphics/animator.lua @@ -0,0 +1,33 @@ +local Component = AsuraEngine.Framework.Require("component") + +AsuraEngine.Animator = Component.Extend("Animator") + +local Animator = AsuraEngine.Animator + +-- Animator inspector variables. +Animator.spriteRenderer = AsuraEngine.Type.SpriteRenderer +Animator.animation = AsuraEngine.Type.Animation + +function Animator:Ctor(entity, animation) + self.base(entity) + self.spriteRenderer = entity:GetSpriteRenderer() + self.animation = animation +end + +function Animator:SetAnimation(animation) + self.animation = animation +end + +function Animator:GetAnimation() + return self.animation +end + +function Animator:OnUpdate(dt) + +end + +function Animator:OnRender() + +end + +return Animator
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/graphics/camera.lua b/source/libs/asura-lib-framework/scripts/graphics/camera.lua new file mode 100644 index 0000000..a989de6 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/graphics/camera.lua @@ -0,0 +1,21 @@ +AsuraEngine.Camera = AsuraEngine.Component.Extend("Camera") + +local Camera = AsuraEngine.Camera + +Camera.isCulling = AsuraEngine.Type.Bool +Camera.isOnScreen = AsuraEngine.Type.Bool + +function Camera.Ctor(self) + self.isCulling = false + self.isOnScreen = false +end + +function Camera.OnUpdate(dt) + +end + +function Camera.OnRender() + +end + +return Camera
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/graphics/canvas.lua b/source/libs/asura-lib-framework/scripts/graphics/canvas.lua new file mode 100644 index 0000000..ce2ca20 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/graphics/canvas.lua @@ -0,0 +1,34 @@ +AsuraEngine.Canvas = AsuraEngine.Component.Extend("Canvas") + +local Canvas = AsuraEngine.Canvas + +function Canvas.Ctor(self, width, height) + self.simCanvas = AsuraEngine.SimCanvas.New(width, height) + self.width = width + self.height = height +end + +function Canvas.GetWidth(self) + return self.width +end + +function Canvas.GetHeight(self) + return self.height +end + +function Canvas.GetSize(self) + return self.width, self.height +end + +function Canvas.OnEnable(self) + if self.simCanvas == nil then + return + end + self.simCanvas:Begin() +end + +function Canvas.OnDisable(self) + +end + +return Canvas
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/graphics/default_shaders.lua b/source/libs/asura-lib-framework/scripts/graphics/default_shaders.lua new file mode 100644 index 0000000..bd54cb9 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/graphics/default_shaders.lua @@ -0,0 +1,5 @@ +--[[ +õshaders. +]] + + diff --git a/source/libs/asura-lib-framework/scripts/graphics/image.lua b/source/libs/asura-lib-framework/scripts/graphics/image.lua new file mode 100644 index 0000000..f5ebaa2 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/graphics/image.lua @@ -0,0 +1,40 @@ +-- 图片资源 +AsuraEngine.Image = AsuraEngine.Asset.Extend("Image") + +local Image = AsuraEngine.Image + +function Image.Ctor(self, path) + local simImage = AsuraEngine.SimImage.New(path) + local w, h = simImage:GetSize() + self.simImage = simImage + self.width = w + self.height = h +end + +function Image.GetWidth(self) + return self.simImage.GetWidth() +end + +function Image.GetHeight(self) + return self.simImage.GetHeight() +end + +function Image.GetSize(self) + return self.simImage.GetSize() +end + +--获得x,y位置的颜色值 +function Image.GetColor(self, x, y) + return self.simImage.GetColor(x, y) +end + +--获得所有像素,返回到一个table里 +function Image.GetPixels(self) + return self.simImage:GetPixels() +end + +--image不可再编辑器编辑,所以没有ToAsset方法 +--function Image.ToAsset() +--end + +return Image
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/graphics/material.lua b/source/libs/asura-lib-framework/scripts/graphics/material.lua new file mode 100644 index 0000000..5a6e5bd --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/graphics/material.lua @@ -0,0 +1,48 @@ +--material是shader的代理 +AsuraEngine.Material = AsuraEngine.Asset.Extend("Material") + +local Material = AsuraEngine.Material + +function Material.Ctor(self) + self.uniforms = {} --uniform变量和值 + self.shader = nil + self.isShared = false +end + +function Material.Clone(self) + +end + +function Material:ToAsset() + +end + +function Material:GetUniform(name) + +end + +function Material:SetFloat(uniform, value) + +end + +function Material:SetTexture(uniform, tex) + +end + +function Material:SetInteger(unifrom, value) + +end + +function Material:SetVec2(uniform, value) + +end + +function Material:SetMat44(uniform, value) + +end + +function Material:GetUniformID() + +end + +return Material
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/graphics/material_manager.lua b/source/libs/asura-lib-framework/scripts/graphics/material_manager.lua new file mode 100644 index 0000000..086a5db --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/graphics/material_manager.lua @@ -0,0 +1,3 @@ +local MaterialManager = AsuraEngine.Manager.New() + +return MaterialManager
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/graphics/mesh2d.lua b/source/libs/asura-lib-framework/scripts/graphics/mesh2d.lua new file mode 100644 index 0000000..05b2e2e --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/graphics/mesh2d.lua @@ -0,0 +1,9 @@ +AsuraEngine.Mesh2D = AsuraEngine.Asset.Extend("Mesh2D") + +local Mesh2D = AsuraEngine.Mesh2D + +function Mesh2D.Ctor(self) + +end + +return Mesh2D
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/graphics/mesh2d_renderer.lua b/source/libs/asura-lib-framework/scripts/graphics/mesh2d_renderer.lua new file mode 100644 index 0000000..09c8c98 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/graphics/mesh2d_renderer.lua @@ -0,0 +1,13 @@ +AsuraEngine.Mesh2DRenderer = AsuraEngine.Renderer.Extend("Mesh2DRenderer") + +local Mesh2DRenderer = AsuraEngine.Mesh2DRenderer + +function Mesh2DRenderer.Ctor(self, material) + self.base(material) +end + +function Mesh2DRenderer.OnRender(self) + +end + +return Mesh2DRenderer
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/graphics/particle_system.lua b/source/libs/asura-lib-framework/scripts/graphics/particle_system.lua new file mode 100644 index 0000000..065a845 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/graphics/particle_system.lua @@ -0,0 +1,20 @@ +require "graphics.sprite_renderer" + +AsuraEngine.ParticleSystem = AsuraEngine.Component.Extend("ParticleSystem") + +local ParticleSystem = AsuraEngine.ParticleSystem + +function ParticleSystem.Ctor(self, entity, def) + self.base(entity) + self.spriteRenderer = AsuraEngine.SpriteRenderer.New() +end + +function ParticleSystem.OnRenderer() + +end + +function ParticleSystem.OnUpdate(dt) + +end + +return ParticleSystem
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/graphics/renderer.lua b/source/libs/asura-lib-framework/scripts/graphics/renderer.lua new file mode 100644 index 0000000..92a6409 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/graphics/renderer.lua @@ -0,0 +1,19 @@ +local Renderer = AsuraEngine.Component.Extend("Renderer") +AsuraEngine.Renderer = Renderer + +function Renderer.Ctor(self) + self.materials = {} + self.material = nil + self.isMultiMaterials = false +end + +--取材质,如果是shared,那么从此材质clone一个 +function Renderer.GetMaterial(self) + +end + +function Renderer.IsMultiMaterials(self) + return self.isMultiMaterials +end + +return Renderer
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/graphics/shader.lua b/source/libs/asura-lib-framework/scripts/graphics/shader.lua new file mode 100644 index 0000000..c411619 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/graphics/shader.lua @@ -0,0 +1,75 @@ +AsuraEngine.Shader = AsuraEngine.Asset.Extend("Shader") + +local helper = AsuraEngine.Framework.Require("graphics/shaderHelper") + +local Shader = AsuraEngine.Shader + +function Shader.Ctor(self) + self.simShader = nil + self.uniforms = {} -- 映射uniform name到location +end + +--编译shader +function Shader.Load(self, vert, frag) + self.uniforms = {} + if self.simShader == nil then + self.simShader = AsuraEngine.SimShader.New(vert, frag) + else + self.simShader:Load(vert, frag) + end + if self.simShader == nil then + --shader编译错误 + return + end + --在编译的时候就获得所有的uniform和loc + local uniforms = helper.GetUniforms(vert, frag) + if uniforms == nil then + return + end + for _, uniform in uniforms do + self.uniforms[uniform] = self.simShader:GetUniformLocation(uniform) + end +end + +function Shader.GetUniformLocation(self, name) + if self.uniforms then + local id = self.uniforms[name] + return id + end + return 0 +end + +function Shader.SendVec2(self, name, vec2) + local id = self:GetUniformLocation(name) + self.simShader:SendUniformVector2(name, vec2) +end + +function Shader.SendVec3(self, name, vec3) + +end + +function Shader.SendVec4(self, name, vec4) + +end + +function Shader.SendTexture(self, name, tex) + +end + +function Shader.SendFloat(self, name, number) + +end + +function Shader.SendInteger(self, name, integer) + +end + +function Shader.SendColor(self, name, color) + +end + +function Shader.SendMat44(self, name, mat44) + +end + +return Shader
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/graphics/shaderHelper.lua b/source/libs/asura-lib-framework/scripts/graphics/shaderHelper.lua new file mode 100644 index 0000000..b1b42a6 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/graphics/shaderHelper.lua @@ -0,0 +1,14 @@ +--[[ +解析vertex shader和 fragment shader,并取得两个shader里面定义的uniforms +]] +local helper = {} + +function helper.GetUniforms(vert, frag) + +end + +function helper.TryCompileShader(vert, frag) + +end + +return helper
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/graphics/shape.lua b/source/libs/asura-lib-framework/scripts/graphics/shape.lua new file mode 100644 index 0000000..51ea8c3 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/graphics/shape.lua @@ -0,0 +1,12 @@ +-- +-- 2D图形 +-- +AsuraEngine.Shape = AsuraEngine.Asset.Extend("Shape") + +local Shape = AsuraEngine.Shape + +function Shape.Ctor(self) + +end + +return Shape
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/graphics/shape_renderer.lua b/source/libs/asura-lib-framework/scripts/graphics/shape_renderer.lua new file mode 100644 index 0000000..80b48b8 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/graphics/shape_renderer.lua @@ -0,0 +1,13 @@ +AsuraEngine.ShapeRenderer = AsuraEngine.Component.Extend("ShapeRenderer") + +local ShapeRenderer = AsuraEngine.ShapeRenderer + +function ShapeRenderer.OnRenderer() + +end + +function ShapeRenderer.OnUpdate(dt) + +end + +return ShapeRenderer
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/graphics/sprite.lua b/source/libs/asura-lib-framework/scripts/graphics/sprite.lua new file mode 100644 index 0000000..9bf05f4 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/graphics/sprite.lua @@ -0,0 +1,10 @@ +local Sprite = AsuraEngine.Asset.Extend("Sprite") +AsuraEngine.Sprite = Sprite + +function Sprite.Ctor(self, image) + self.image = image +end + +function Sprite.ToAsset(self) + +end
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/graphics/sprite_batch_renderer.lua b/source/libs/asura-lib-framework/scripts/graphics/sprite_batch_renderer.lua new file mode 100644 index 0000000..9ec73d2 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/graphics/sprite_batch_renderer.lua @@ -0,0 +1,9 @@ +AsuraEngine.SpriteBatchRenderer = AsuraEngine.Component.Extend("SpriteBatchRenderer") + +local SpriteBatchRenderer = AsuraEngine.SpriteBatchRenderer + +function SpriteBatchRenderer.Ctor(self) + +end + +return SpriteBatchRenderer
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/graphics/sprite_renderer.lua b/source/libs/asura-lib-framework/scripts/graphics/sprite_renderer.lua new file mode 100644 index 0000000..0a41e08 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/graphics/sprite_renderer.lua @@ -0,0 +1,14 @@ +require "graphics.renderer" + +local SpriteRenderer = AsuraEngine.Renderer.Extend("Spriterenderer") +AsuraEngine.SpriteRenderer = SpriteRenderer + +function SpriteRenderer.Ctor(self) + self.materials = {} +end + +function SpriteRenderer:OnRender() + +end + +return SpriteRenderer
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/gui/button.lua b/source/libs/asura-lib-framework/scripts/gui/button.lua new file mode 100644 index 0000000..b122931 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/gui/button.lua @@ -0,0 +1,21 @@ +AsuraEngine.Button = AsuraEngine.Component.Extend("Button") + +local Button = AsuraEngine.Button + +function Button.Ctor(self) + +end + +function Button.OnEvent(e) + +end + +function Button.OnRender() + +end + +function Button.OnUpdate(dt) + +end + +return Button
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/gui/text.lua b/source/libs/asura-lib-framework/scripts/gui/text.lua new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/gui/text.lua diff --git a/source/libs/asura-lib-framework/scripts/gui/widget.lua b/source/libs/asura-lib-framework/scripts/gui/widget.lua new file mode 100644 index 0000000..430ade0 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/gui/widget.lua @@ -0,0 +1,14 @@ +--[[ +Imgui,用在游戏里面 +]] +local Widget = AsuraEngine.Component("Widget") + +function Widget.Ctor(self) + +end + +function Widget.OnEvent(self, e) + +end + +return Widget
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/managers/scene_manager.lua b/source/libs/asura-lib-framework/scripts/managers/scene_manager.lua new file mode 100644 index 0000000..7886dc6 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/managers/scene_manager.lua @@ -0,0 +1,16 @@ +AsuraEngine.SceneManager = AsuraEngine.Class("SceneManager") + +local SceneManager = AsuraEngine.SceneManager + +--游戏里的所有场景 +SceneManager.scenes = {} + +function SceneManager.Ctor() + +end + +function SceneManager.GetSceneByGUID() + +end + +return SceneManager
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/managers/sprite_manager.lua b/source/libs/asura-lib-framework/scripts/managers/sprite_manager.lua new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/managers/sprite_manager.lua diff --git a/source/libs/asura-lib-framework/scripts/math/curve.lua b/source/libs/asura-lib-framework/scripts/math/curve.lua new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/math/curve.lua diff --git a/source/libs/asura-lib-framework/scripts/path/path.lua b/source/libs/asura-lib-framework/scripts/path/path.lua new file mode 100644 index 0000000..1fc9b3a --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/path/path.lua @@ -0,0 +1,13 @@ +local Path = AsuraEngine.Asset.New("path") + +function Path:Ctor() + +end + +-- ToAssetѶpathתΪ.assetļʽ +function Path.ToAsset(path) + local builder = AsuraEngine.AssetBuilder.Get() + +end + +return Path
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/path/path_calculator.lua b/source/libs/asura-lib-framework/scripts/path/path_calculator.lua new file mode 100644 index 0000000..d44da08 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/path/path_calculator.lua @@ -0,0 +1,12 @@ +--[[ +ڱ༭componentsб +]] +local PathCalculator = AsuraEngine.Component.New("PathCalculator") + +PathCalculator.path = AsuraEngine.Asset.Type("path", "·") + +function PathCalculator:ctor(path) + self.path = path +end + +return PathCalculator
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/path/path_manager.lua b/source/libs/asura-lib-framework/scripts/path/path_manager.lua new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/path/path_manager.lua diff --git a/source/libs/asura-lib-framework/scripts/scene.lua b/source/libs/asura-lib-framework/scripts/scene.lua new file mode 100644 index 0000000..11ac86c --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/scene.lua @@ -0,0 +1,22 @@ +-- +-- Scene是一系列gameobject的集合。 +-- +AsuraEngine.Scene = AsuraEngine.Asset.Extend("Scene") + +local Scene = AsuraEngine.Scene + +function Scene.Ctor(self) + self.rootGameObjects = {} --当前场景的所有root entity + self.super.Ctor(self) +end + +--获取当前的场景 +function Scene.GetCurrent() + +end + +function Scene.ToAsset() + +end + +return Scene
\ No newline at end of file diff --git a/source/libs/asura-lib-framework/scripts/transform.lua b/source/libs/asura-lib-framework/scripts/transform.lua new file mode 100644 index 0000000..1d34ae6 --- /dev/null +++ b/source/libs/asura-lib-framework/scripts/transform.lua @@ -0,0 +1,13 @@ +-- transform的起点在左下角,逆时针为正向 +AsuraEngine.Transform = AsuraEngine.Class("Transform") +local Transform = AsuraEngine.Transform + +function Transform.Ctor(self) + self.position = {x=0, y=0} + self.rotation = 0 + self.size = {w=0, h=0} +end + +function Transform.Move(self) + +end
\ No newline at end of file diff --git a/source/libs/asura-lib-json/json.cpp b/source/libs/asura-lib-json/json.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-json/json.cpp diff --git a/source/libs/asura-lib-json/json.h b/source/libs/asura-lib-json/json.h new file mode 100644 index 0000000..2bdaf53 --- /dev/null +++ b/source/libs/asura-lib-json/json.h @@ -0,0 +1,14 @@ +#ifndef __ASURA_JSON_H__ +#define __ASURA_JSON_H__ + +namespace AsuraEngine +{ + namespace Json + { + + + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-json/json_module.cpp b/source/libs/asura-lib-json/json_module.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-json/json_module.cpp diff --git a/source/libs/asura-lib-json/json_module.h b/source/libs/asura-lib-json/json_module.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-json/json_module.h diff --git a/source/libs/asura-lib-openal/sound.cpp b/source/libs/asura-lib-openal/sound.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-openal/sound.cpp diff --git a/source/libs/asura-lib-openal/sound.h b/source/libs/asura-lib-openal/sound.h new file mode 100644 index 0000000..6c2d7c2 --- /dev/null +++ b/source/libs/asura-lib-openal/sound.h @@ -0,0 +1,31 @@ +#ifndef __ASURA_ENGINE_SOUND_H__ +#define __ASURA_ENGINE_SOUND_H__ + +#include <asura-lib-utils/scripting/portable.hpp> + +namespace AsuraEngine +{ + namespace Audio + { + + /// + /// Ƶļ + /// + class Sound ASURA_FINAL + : public AEScripting::Portable<Sound> + { + public: + + Sound(); + ~Sound(); + + private: + + + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-openal/sound_decode_task.cpp b/source/libs/asura-lib-openal/sound_decode_task.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-openal/sound_decode_task.cpp diff --git a/source/libs/asura-lib-openal/sound_decode_task.h b/source/libs/asura-lib-openal/sound_decode_task.h new file mode 100644 index 0000000..d39013f --- /dev/null +++ b/source/libs/asura-lib-openal/sound_decode_task.h @@ -0,0 +1,25 @@ +#ifndef __ASURA_OPENAL_SOUND_DECODER_TASK_H__ +#define __ASURA_OPENAL_SOUND_DECODER_TASK_H__ + +#include <asura-lib-utils/threading/thread_task.h> + +namespace AsuraEngine +{ + namespace OpenAL + { + + /// + /// Ƶļ + /// + class SoundDecodeTask : public AEThreading::ThreadTask + { + public: + + private: + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-openal/sound_decoder.cpp b/source/libs/asura-lib-openal/sound_decoder.cpp new file mode 100644 index 0000000..ad9f761 --- /dev/null +++ b/source/libs/asura-lib-openal/sound_decoder.cpp @@ -0,0 +1,29 @@ +#ifndef __ASURA_ENGINE_SOUND_DECODER_H__ +#define __ASURA_ENGINE_SOUND_DECODER_H__ + +#include "Sound.h" +#include "FileSystem/DataBuffer.h" + +namespace AsuraEngine +{ + namespace Audio + { + + /// + /// Ƶļ + /// + class SoundDecoder + { + public: + + SoundDecoder(); + virtual ~SoundDecoder(); + + virtual Sound* Decode(const Filesystem::DataBuffer* db); + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-openal/sound_decoder.h b/source/libs/asura-lib-openal/sound_decoder.h new file mode 100644 index 0000000..2a3f087 --- /dev/null +++ b/source/libs/asura-lib-openal/sound_decoder.h @@ -0,0 +1,30 @@ +#ifndef __ASURA_ENGINE_SOUND_DECODER_H__ +#define __ASURA_ENGINE_SOUND_DECODER_H__ + +#include <asura-lib-utils/io/data_buffer.h> + +#include "sound.h" + +namespace AsuraEngine +{ + namespace Audio + { + + /// + /// Ƶļ + /// + class SoundDecoder + { + public: + + SoundDecoder(); + virtual ~SoundDecoder(); + + virtual Sound* Decode(const AEIO::DataBuffer* db); + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/exceptions/exception.cpp b/source/libs/asura-lib-utils/exceptions/exception.cpp new file mode 100644 index 0000000..dbb36ca --- /dev/null +++ b/source/libs/asura-lib-utils/exceptions/exception.cpp @@ -0,0 +1,47 @@ +#include "Exception.h" + +#include <cstdarg> +#include <iostream> + +namespace AsuraEngine +{ + + Exception::Exception(const char *fmt, ...) + { + va_list args; + int size_buffer = 256, size_out; + char *buffer; + while (true) + { + buffer = new char[size_buffer]; + memset(buffer, 0, size_buffer); + + va_start(args, fmt); + size_out = vsnprintf(buffer, size_buffer, fmt, args); + va_end(args); + + // see http://perfec.to/vsnprintf/pasprintf.c + // if size_out ... + // == -1 --> output was truncated + // == size_buffer --> output was truncated + // == size_buffer-1 --> ambiguous, /may/ have been truncated + // > size_buffer --> output was truncated, and size_out + // bytes would have been written + if (size_out == size_buffer || size_out == -1 || size_out == size_buffer - 1) + size_buffer *= 2; + else if (size_out > size_buffer) + size_buffer = size_out + 2; // to avoid the ambiguous case + else + break; + + delete[] buffer; + } + message = std::string(buffer); + delete[] buffer; + } + + Exception::~Exception() throw() + { + } + +} diff --git a/source/libs/asura-lib-utils/exceptions/exception.h b/source/libs/asura-lib-utils/exceptions/exception.h new file mode 100644 index 0000000..57c9ed6 --- /dev/null +++ b/source/libs/asura-lib-utils/exceptions/exception.h @@ -0,0 +1,44 @@ +#ifndef __ASURA_ENGINE_EXCEPTION_H__ +#define __ASURA_ENGINE_EXCEPTION_H__ + +#include <string> +#include <exception> + +namespace AsuraEngine +{ + + /** + * A convenient vararg-enabled exception class. + **/ + class Exception : public std::exception + { + public: + + /** + * Creates a new Exception according to printf-rules. + * + * See: http://www.cplusplus.com/reference/clibrary/cstdio/printf/ + * + * @param fmt The format string (see printf). + **/ + Exception(const char *fmt, ...); + virtual ~Exception() throw(); + + /** + * Returns a string containing reason for the exception. + * @return A description of the exception. + **/ + inline virtual const char *what() const throw() + { + return message.c_str(); + } + + private: + + std::string message; + + }; // Exception + +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/binding/_compressor.cpp b/source/libs/asura-lib-utils/io/binding/_compressor.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-utils/io/binding/_compressor.cpp diff --git a/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp b/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp new file mode 100644 index 0000000..cd73b31 --- /dev/null +++ b/source/libs/asura-lib-utils/io/binding/_data_buffer.cpp @@ -0,0 +1,123 @@ +#include "../data_buffer.h" + +using namespace Luax; + +namespace AsuraEngine +{ + namespace IO + { + + LUAX_REGISTRY(DataBuffer) + { + LUAX_REGISTER_METHODS(state, + { "New", _New }, + { "GetData", _GetData }, + { "GetSize", _GetSize }, + { "Refactor", _Refactor }, + { "Load", _Load }, + { "Clear", _Clear } + ); + } + + LUAX_POSTPROCESS(DataBuffer) + { + } + + // databuffer = DataBuffer.New(lstring) + // databuffer = DataBuffer.New(size) + LUAX_IMPL_METHOD(DataBuffer, _New) + { + LUAX_STATE(L); + + if (state.IsType(1, LUA_TSTRING)) + { + size_t size; + const byte* bytes = lua_tolstring(L, 1, &size); + DataBuffer* buffer = new DataBuffer(bytes, size); + buffer->PushLuaxUserdata(state); + return 1; + } + else if (state.IsType(1, LUA_TNUMBER)) + { + size_t size = lua_tonumber(L, 1); + DataBuffer* buffer = new DataBuffer(size); + buffer->PushLuaxUserdata(state); + return 1; + } + else + { + return state.ErrorType(1, "number or string"); + } + } + + // lsting, len = databuffer:GetData() + LUAX_IMPL_METHOD(DataBuffer, _GetData) + { + LUAX_SETUP(L, "U"); + + DataBuffer* self = state.GetUserdata<DataBuffer>(1); + lua_pushlstring(L, self->GetData(), self->GetSize()); + return 1; + } + + // length = databuffer:GetSize() + LUAX_IMPL_METHOD(DataBuffer, _GetSize) + { + LUAX_SETUP(L, "U"); + + DataBuffer* self = state.GetUserdata<DataBuffer>(1); + lua_pushinteger(L, self->GetSize()); + return 1; + } + + // databuffer:Refactor(size) + LUAX_IMPL_METHOD(DataBuffer, _Refactor) + { + LUAX_PREPARE(L, DataBuffer); + + size_t size = state.CheckValue<int>(2); + self->Refactor(size); + return 0; + } + + // size = databuffer:Load(lstring) + // size = databuffer:Load(src) + LUAX_IMPL_METHOD(DataBuffer, _Load) + { + LUAX_STATE(L); + + DataBuffer* buffer = state.GetUserdata<DataBuffer>(1); + const byte* data; + size_t size; + if (state.IsType(2, LUA_TSTRING)) + { + data = lua_tolstring(L, 2, &size); + size_t len = buffer->Load(data, size); + state.Push(len); + return 1; + } + else if(state.IsType(2, LUA_TUSERDATA)) + { + DataBuffer* src = state.CheckUserdata<DataBuffer>(2); + size_t len = buffer->Load(*src); + state.Push(len); + return 1; + } + else + { + return state.ErrorType(1, "lstring or DataBuffer"); + } + } + + // databuffer:Clear() + LUAX_IMPL_METHOD(DataBuffer, _Clear) + { + LUAX_SETUP(L, "U"); + + DataBuffer* self = state.GetUserdata<DataBuffer>(1); + self->Clear(); + return 0; + } + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/binding/_file.cpp b/source/libs/asura-lib-utils/io/binding/_file.cpp new file mode 100644 index 0000000..c44bc90 --- /dev/null +++ b/source/libs/asura-lib-utils/io/binding/_file.cpp @@ -0,0 +1,223 @@ +#include "../file.h" + +namespace AsuraEngine +{ + namespace IO + { + + LUAX_REGISTRY(File) + { + LUAX_REGISTER_METHODS(state, + { "New", _New }, + { "Open", _Open }, + { "Close", _Close }, + { "IsOpen", _IsOpen }, + { "GetMode", _GetMode }, + { "GetSize", _GetSize }, + { "Read", _Read }, + { "IsEOF", _IsEOF }, + { "Write", _Write }, + { "Flush", _Flush }, + { "Tell", _Tell }, + { "Seek", _Seek }, + { "SetBuffer", _SetBuffer }, + { "GetBuffer", _GetBuffer }, + { "GetFileName", _GetFileName }, + { "GetExtension", _GetExtension }, + { "GetName", _GetName } + ); + } + + LUAX_POSTPROCESS(File) + { + LUAX_REGISTER_ENUM(state, "EFileMode", + { "CLOSED", FILE_MODE_CLOSED }, + { "READ", FILE_MODE_READ }, + { "WRITE", FILE_MODE_WRITE }, + { "APPEND", FILE_MODE_APPEND } + ); + + LUAX_REGISTER_ENUM(state, "EBufferMode", + { "NONE", BUFFER_MODE_NONE}, + { "LINE", BUFFER_MODE_LINE}, + { "FULL", BUFFER_MODE_FULL} + ); + } + + // file = File.New(name) + LUAX_IMPL_METHOD(File, _New) + { + LUAX_STATE(L); + + cc8* name = state.CheckValue<cc8*>(1); + File* file = new File(name); + file->PushLuaxUserdata(state); + return 1; + } + + // successsed = file:Open(mode) + LUAX_IMPL_METHOD(File, _Open) + { + LUAX_PREPARE(L, File); + + File::FileMode mode = (File::FileMode)state.CheckValue<int>(2); + state.Push(self->Open(mode)); + return 1; + } + + // successed = file:Close() + LUAX_IMPL_METHOD(File, _Close) + { + LUAX_PREPARE(L, File); + + state.Push(self->Close()); + return 1; + } + + // opened = file:IsOpen() + LUAX_IMPL_METHOD(File, _IsOpen) + { + LUAX_PREPARE(L, File); + + state.Push(self->IsOpen()); + return 1; + } + + // mode = file:GetMode() + LUAX_IMPL_METHOD(File, _GetMode) + { + LUAX_PREPARE(L, File); + + File::FileMode mode = self->GetMode(); + state.Push((int)mode); + return 1; + } + + // size = file:GetSize() + LUAX_IMPL_METHOD(File, _GetSize) + { + LUAX_PREPARE(L, File); + + state.Push(self->GetSize()); + return 1; + } + + // size = file:Read(dst, len) + // returns: + // size ʵʶĴС + // params: + // self ļ + // dst Ŀ껺 + // len ĴС + LUAX_IMPL_METHOD(File, _Read) + { + LUAX_PREPARE(L, File); + + DataBuffer* db = state.CheckUserdata<DataBuffer>(2); + if (!db) return state.ErrorType(2, "DataBuffer"); + int len = state.CheckValue<int>(3); + int size = self->Read(db, len); + state.Push(size); + return 1; + } + + // isEOF = file:IsEOF() + LUAX_IMPL_METHOD(File, _IsEOF) + { + LUAX_PREPARE(L, File); + + state.Push(self->IsEOF()); + return 1; + } + + // isWrite = file:Write(data buffer[, size]) + LUAX_IMPL_METHOD(File, _Write) + { + LUAX_PREPARE(L, File); + + DataBuffer* db = state.CheckUserdata<DataBuffer>(2); + if (!db) return state.ErrorType(2, "DataBuffer"); + state.Push(self->Write(db)); + return 1; + } + + // isFlushed = file:Flush() + LUAX_IMPL_METHOD(File, _Flush) + { + LUAX_PREPARE(L, File); + + state.Push(self->Flush()); + return 1; + } + + // pos = file:Tell() + LUAX_IMPL_METHOD(File, _Tell) + { + LUAX_PREPARE(L, File); + + state.Push(self->Tell()); + return 1; + } + + // isSeek = file:Seek(pos) + LUAX_IMPL_METHOD(File, _Seek) + { + LUAX_PREPARE(L, File); + + int pos = state.CheckValue<int>(2); + state.Push(self->Seek(pos)); + return 1; + } + + // isSetted = file:SetBuffer(mode, size) + LUAX_IMPL_METHOD(File, _SetBuffer) + { + LUAX_PREPARE(L, File); + + BufferMode mode = (BufferMode)state.CheckValue<int>(2); + int size = state.CheckValue<int>(3); + state.Push(self->SetBuffer(mode, size)); + return 1; + } + + // size, mode = file:GetBuffer() + LUAX_IMPL_METHOD(File, _GetBuffer) + { + LUAX_PREPARE(L, File); + + size_t size = 0; + BufferMode mode = self->GetBuffer(ASURA_OUT size); + state.Push((int)size); + state.Push((int)mode); + return 2; + } + + // name = file:GetFileName() + LUAX_IMPL_METHOD(File, _GetFileName) + { + LUAX_PREPARE(L, File); + + state.Push(self->GetFileName()); + return 1; + } + + // name = file:GetExtension() + LUAX_IMPL_METHOD(File, _GetExtension) + { + LUAX_PREPARE(L, File); + + state.Push(self->GetExtension()); + return 1; + } + + // name = file:GetName() + LUAX_IMPL_METHOD(File, _GetName) + { + LUAX_PREPARE(L, File); + + state.Push(self->GetName()); + return 1; + } + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/binding/_file_data.cpp b/source/libs/asura-lib-utils/io/binding/_file_data.cpp new file mode 100644 index 0000000..09a0643 --- /dev/null +++ b/source/libs/asura-lib-utils/io/binding/_file_data.cpp @@ -0,0 +1,60 @@ +#include "../file_data.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace IO + { + + LUAX_REGISTRY(FileData) + { + LUAX_REGISTER_METHODS(state, + { "GetFileName", _GetFileName }, + { "GetExtension", _GetExtension }, + { "GetName", _GetName }, + { "GetDataBuffer", _GetDataBuffer } + ); + } + + LUAX_POSTPROCESS(FileData) + { + } + + // filename = filedata:GetFileName() + LUAX_IMPL_METHOD(FileData, _GetFileName) + { + LUAX_PREPARE(L, FileData); + string filename = self->GetFileName(); + state.Push(filename); + return 1; + } + + // extension = filedata:GetExtension() + LUAX_IMPL_METHOD(FileData, _GetExtension) + { + LUAX_PREPARE(L, FileData); + string extension = self->GetExtension(); + state.Push(extension); + return 1; + } + + // name = filedata:GetName() + LUAX_IMPL_METHOD(FileData, _GetName) + { + LUAX_PREPARE(L, FileData); + string extension = self->GetName(); + state.Push(extension); + return 1; + } + + // databuffer = filedata:GetDataBuffer() + LUAX_IMPL_METHOD(FileData, _GetDataBuffer) + { + LUAX_PREPARE(L, FileData); + self->PushLuaxMemberRef(state, self->mDataRef); + return 1; + } + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/binding/_file_system.cpp b/source/libs/asura-lib-utils/io/binding/_file_system.cpp new file mode 100644 index 0000000..3843451 --- /dev/null +++ b/source/libs/asura-lib-utils/io/binding/_file_system.cpp @@ -0,0 +1,265 @@ +#include "../file_system.h" + +using namespace Luax; + +namespace AsuraEngine +{ + namespace IO + { + +#define PREPARE(l) \ + LUAX_STATE(l); \ + Filesystem* fs = Filesystem::Get(); + + LUAX_REGISTRY(Filesystem) + { + LUAX_REGISTER_METHODS(state, + { "Init", _Init }, + { "Mount", _Mount }, + { "Unmount", _Unmount }, + { "GetMountPoint", _GetMountPoint }, + { "SetWriteDirectory", _SetWriteDirectory }, + { "GetWriteDirectory", _GetWriteDirectory }, + { "CreateFile", _CreateFile }, + { "CreateDirectory", _CreateDirectory }, + { "Write", _Write }, + { "Append", _Append }, + { "Remove", _Remove }, + { "Read", _Read }, + { "GetFileInfo", _GetFileInfo }, + { "GetDirectoryItems", _GetDirectoryItems } + ); + } + + LUAX_POSTPROCESS(Filesystem) + { + LUAX_REGISTER_ENUM(state, "EFileType", + { "FILE", FILE_TYPE_FILE }, + { "DIRECTORY", FILE_TYPE_DIRECTORY }, + { "SYMLINK", FILE_TYPE_SYMLINK }, + { "OTHER", FILE_TYPE_OTHER } + ); + } + + // Filesystem.Init(arg0) + LUAX_IMPL_METHOD(Filesystem, _Init) + { + PREPARE(L); + + const char* arg0 = state.CheckValue<const char*>(1); + fs->Init(arg0); + return 0; + } + + // successed = Filesystem.Mount(path, mountpoint[, prepend = false]) + // successed = Filesystem.Mount(data buffer, archievename, mountpoint[, prepend = false]) + LUAX_IMPL_METHOD(Filesystem, _Mount) + { + PREPARE(L); + bool mounted = false; + + if (state.IsType(1, LUA_TSTRING)) + { + cc8* path = state.GetValue<cc8*>(1, ""); + cc8* moutpoint = state.GetValue<cc8*>(2, "/"); + bool prepend = state.GetValue<bool>(3, false); + mounted = fs->Mount(path, moutpoint, prepend); + } + else if (state.IsType(1, LUA_TUSERDATA)) + { + DataBuffer* db = state.CheckUserdata<DataBuffer>(1); + if (!db) + return state.ErrorType(1, "Data Buffer"); + cc8* arcname = state.GetValue<cc8*>(2, ""); + cc8* mountpoint = state.GetValue<cc8*>(3, "/"); + bool prepend = state.GetValue<bool>(4, false); + mounted = fs->Mount(db, arcname, mountpoint, prepend); + // retain + fs->LuaxRetain<DataBuffer>(state, db); + } + state.Push(mounted); + return 1; + } + + // successed = Filesystem.Unmount(path) + // successed = Filesystem.Unmount(data buffer) + LUAX_IMPL_METHOD(Filesystem, _Unmount) + { + PREPARE(L); + bool unmounted = false; + + if (state.IsType(1, LUA_TSTRING)) + { + cc8* path = state.GetValue<cc8*>(1, ""); + unmounted = fs->Unmount(path); + } + else if (state.IsType(1, LUA_TUSERDATA)) + { + DataBuffer* db = state.CheckUserdata<DataBuffer>(1); + if (!db) + return state.ErrorType(1, "Data Buffer"); + unmounted = fs->Unmount(db); + if (unmounted) + fs->LuaxRelease<DataBuffer>(state, db); + } + state.Push(unmounted); + return 1; + } + + // moutpoint = Filesystem.GetMountPoint(path) + LUAX_IMPL_METHOD(Filesystem, _GetMountPoint) + { + PREPARE(L); + + cc8* path = state.CheckValue<cc8*>(1); + std::string mp; + if (fs->GetMountPoint(path, ASURA_OUT mp)) + state.Push(mp); + else + state.PushNil(); + + return 1; + } + + // Filesystem.SetWriteDirectory(dir) + LUAX_IMPL_METHOD(Filesystem, _SetWriteDirectory) + { + PREPARE(L); + + cc8* dir = state.CheckValue<cc8*>(1); + fs->SetWriteDirectory(dir); + return 0; + } + + // dir = Filesystem.GetWriteDirectory() + LUAX_IMPL_METHOD(Filesystem, _GetWriteDirectory) + { + PREPARE(L); + + std::string dir = fs->GetWriteDirectory(); + state.Push(dir); + return 1; + } + + // file = Filesystem.CreateFile(name) + LUAX_IMPL_METHOD(Filesystem, _CreateFile) + { + PREPARE(L); + + cc8* name = state.CheckValue<cc8*>(1); + File* file = fs->NewFile(name); + if (file) + file->PushLuaxUserdata(state); + else + state.PushNil(); + return 1; + } + + // successed = Filesystem.CreateDirectory(name) + LUAX_IMPL_METHOD(Filesystem, _CreateDirectory) + { + PREPARE(L); + + cc8* path = state.CheckValue<cc8*>(1); + state.Push(fs->NewDirectory(path)); + return 1; + } + + // successed = Filesystem.Write(path, data buffer) + LUAX_IMPL_METHOD(Filesystem, _Write) + { + PREPARE(L); + + cc8* path = state.CheckValue<cc8*>(1); + DataBuffer* db = state.CheckUserdata<DataBuffer>(2); + state.Push(fs->Write(path, db)); + return 1; + } + + // successed = Filesystem.Append(path, data buffer) + LUAX_IMPL_METHOD(Filesystem, _Append) + { + PREPARE(L); + + cc8* path = state.CheckValue<cc8*>(1); + DataBuffer* db = state.CheckUserdata<DataBuffer>(2); + state.Push(fs->Append(path, db)); + return 1; + } + + // successed = Filesystem.Remove(path) + LUAX_IMPL_METHOD(Filesystem, _Remove) + { + PREPARE(L); + + cc8* path = state.CheckValue<cc8*>(1); + state.Push(fs->Remove(path)); + return 1; + } + + // filedata = Filesystem.Read(path) + LUAX_IMPL_METHOD(Filesystem, _Read) + { + PREPARE(L); + + cc8* path = state.CheckValue<cc8*>(1); + FileData* fd = fs->Read(path); + if (fd) + { + fd->mData->PushLuaxUserdata(state); + fd->SetLuaxMemberRef(state, fd->mDataRef, -1); // fd->mDataRef = data buffer + state.Pop(1); // data buffer + fd->PushLuaxUserdata(state); + } + else + { + state.PushNil(); + } + return 1; + } + + // fileinfo = Filesystem.GetFileInfo(path) + LUAX_IMPL_METHOD(Filesystem, _GetFileInfo) + { + PREPARE(L); + + cc8* path = state.CheckValue<cc8*>(1); + FileInfo info; + if (fs->GetFileInfo(path, &info)) + { + lua_newtable(L); // info table + state.SetField(-1, "size", info.size); + state.SetField(-1, "modtime", info.modtime); + state.SetField(-1, "type", info.type); + } + else + { + state.PushNil(); + } + return 1; + } + + // items = Filesystem.GetDirectoryItems(path) + LUAX_IMPL_METHOD(Filesystem, _GetDirectoryItems) + { + PREPARE(L); + + cc8* path = state.CheckValue<cc8*>(1); + std::vector<std::string> items; + if(fs->GetDirectoryItems(path, ASURA_OUT items)) + { + lua_newtable(L); // item list + for (int i = 0; i < items.size(); ++i) + { + state.SetFieldByIndex(-1, i + 1, items[i]); + } + } + else + { + state.PushNil(); + } + return 1; + } + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/binding/_io_task.cpp b/source/libs/asura-lib-utils/io/binding/_io_task.cpp new file mode 100644 index 0000000..b3c5988 --- /dev/null +++ b/source/libs/asura-lib-utils/io/binding/_io_task.cpp @@ -0,0 +1,46 @@ +#include "../io_task.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace IO + { + + LUAX_REGISTRY(IOTask) + { + LUAX_REGISTER_METHODS(state, + { "New", _New } + ); + } + + LUAX_POSTPROCESS(IOTask) + { + LUAX_REGISTER_ENUM(state, "EIOTaskType", + { "READ", IOTASK_TYPE_READ }, + { "WRITE", IOTASK_TYPE_WRITE }, + { "APPEND", IOTASK_TYPE_APPEND } + ); + + } + + // task = IOTask.New(path, buffer, type, callback) + LUAX_IMPL_METHOD(IOTask, _New) + { + LUAX_STATE(L); + + cc8* path = state.CheckValue<cc8*>(1); + DataBuffer* db = state.CheckUserdata<DataBuffer>(2); + IOTaskType type = (IOTaskType)state.CheckValue<int>(3); + bool cbk = state.GetTop() >= 4 && state.IsType(4, LUA_TFUNCTION); + + IOTask* task = new IOTask(path, db, type); + task->SetLuaxMemberRef(state, task->mBufferRef, 2); + if(cbk) + task->SetLuaxMemberRef(state, task->mCallback, 4); + task->PushLuaxUserdata(state); + return 1; + } + + } +} diff --git a/source/libs/asura-lib-utils/io/compressor.cpp b/source/libs/asura-lib-utils/io/compressor.cpp new file mode 100644 index 0000000..095eff4 --- /dev/null +++ b/source/libs/asura-lib-utils/io/compressor.cpp @@ -0,0 +1,11 @@ +#include "compressor.h" + +namespace AsuraEngine +{ + namespace IO + { + + + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/compressor.h b/source/libs/asura-lib-utils/io/compressor.h new file mode 100644 index 0000000..30a074c --- /dev/null +++ b/source/libs/asura-lib-utils/io/compressor.h @@ -0,0 +1,30 @@ +#ifndef __ASURA_COMPRESSOR_H__ +#define __ASURA_COMPRESSOR_H__ + +#include "../scripting/portable.hpp" + +namespace AsuraEngine +{ + namespace IO + { + + class Compressor ASURA_FINAL + : public AEScripting::Portable<Compressor> + { + public: + + LUAX_DECL_SINGLETON(Compressor); + + private: + + LUAX_DECL_METHOD(_Compress); + LUAX_DECL_METHOD(_Decompress); + + + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/data_buffer.cpp b/source/libs/asura-lib-utils/io/data_buffer.cpp new file mode 100644 index 0000000..5049b38 --- /dev/null +++ b/source/libs/asura-lib-utils/io/data_buffer.cpp @@ -0,0 +1,102 @@ +#include <cstdlib> +#include <cstring> +#include "data_buffer.h" + +using namespace AEThreading; + +namespace AsuraEngine +{ + namespace IO + { + + DataBuffer::DataBuffer(DataBuffer& src) + { + Load(src); + } + + DataBuffer::DataBuffer(std::size_t size) + : mSize(size) + , mBytes(nullptr) + { + lock(mMutex); + mBytes = new byte[size]; + memset(mBytes, 0, size); + } + + DataBuffer::DataBuffer(const void* data, std::size_t size) + : mSize(size) + , mBytes(nullptr) + { + Load(data, size); + } + + DataBuffer::~DataBuffer() + { + delete[] mBytes; + } + + void DataBuffer::Refactor(size_t size) + { + lock(mMutex); + if (!mBytes || mSize != size) + { + delete[] mBytes; + mBytes = new byte[size]; + mSize = size; + } + memset(mBytes, 0, size * sizeof(byte)); + } + + size_t DataBuffer::Load(DataBuffer& db) + { + return Load(db.GetData(), db.GetSize()); + } + + size_t DataBuffer::Load(const void* data, std::size_t size) + { + lock(mMutex); + size_t len = mSize > size ? size : mSize; + memcpy(mBytes, data, len); + return len; + } + + void DataBuffer::Move(void* bytes, std::size_t size) + { + lock(mMutex); + if (!mBytes) + { + delete[] mBytes; + } + mBytes = (byte*)bytes; + mSize = size; + } + + byte* DataBuffer::GetData() + { + return mBytes; + } + + void DataBuffer::Clear() + { + lock(mMutex); + if (mBytes) + memset(mBytes, 0, mSize); + } + + std::size_t DataBuffer::GetSize() + { + return mSize; + } + + void DataBuffer::Lock() + { + mMutex.Lock(); + } + + void DataBuffer::Unlock() + { + mMutex.Unlock(); + } + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/data_buffer.h b/source/libs/asura-lib-utils/io/data_buffer.h new file mode 100644 index 0000000..445bdf4 --- /dev/null +++ b/source/libs/asura-lib-utils/io/data_buffer.h @@ -0,0 +1,62 @@ +#ifndef __ASURA_ENGINE_DATABUFFER_H__ +#define __ASURA_ENGINE_DATABUFFER_H__ + +#include <cstdlib> + +#include "../scripting/portable.hpp" +#include "../threading/mutex.h" + +namespace AsuraEngine +{ + namespace IO + { + + /// + /// ڴݵķװеʹData bufferװֱʹconst void*ͨresource managerȡ + /// + class DataBuffer ASURA_FINAL + : public AEScripting::Portable<DataBuffer> + { + public: + + LUAX_DECL_FACTORY(DataBuffer); + + DataBuffer(DataBuffer& src); + DataBuffer(std::size_t size); + DataBuffer(const void* bytes, std::size_t size); + ~DataBuffer(); + + byte* GetData(); + size_t GetSize(); + + void Refactor(size_t size); + size_t Load(DataBuffer& db); + size_t Load(const void* bytes, std::size_t size); + void Move(void* bytes, std::size_t size); + void Clear(); + + void Lock(); + void Unlock(); + + private: + + byte* mBytes; + size_t mSize; + + AEThreading::Mutex mMutex; + + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_GetData); + LUAX_DECL_METHOD(_GetSize); + LUAX_DECL_METHOD(_Refactor); + LUAX_DECL_METHOD(_Load); + LUAX_DECL_METHOD(_Clear); + + }; + + } +} + +namespace AEIO = AsuraEngine::IO; + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/decoded_data.cpp b/source/libs/asura-lib-utils/io/decoded_data.cpp new file mode 100644 index 0000000..358a7a5 --- /dev/null +++ b/source/libs/asura-lib-utils/io/decoded_data.cpp @@ -0,0 +1,21 @@ +#include "../exceptions/exception.h" + +#include "decoded_data.h" + +namespace AsuraEngine +{ + namespace IO + { + + DecodedData::DecodedData(const DataBuffer& databuffer) + { + Decode(databuffer); + } + + DecodedData::~DecodedData() + { + + } + + } +} diff --git a/source/libs/asura-lib-utils/io/decoded_data.h b/source/libs/asura-lib-utils/io/decoded_data.h new file mode 100644 index 0000000..e201e91 --- /dev/null +++ b/source/libs/asura-lib-utils/io/decoded_data.h @@ -0,0 +1,42 @@ +#ifndef __ASURA_ENGINE_DATA_H__ +#define __ASURA_ENGINE_DATA_H__ + +#include <cstdlib> + +#include "../scripting/portable.hpp" + +#include "data_buffer.h" + +namespace AsuraEngine +{ + namespace IO + { + + /// + /// һ̹߳data̳дࡣͼƬݡƵݵȣһ߳нԭļڲݸʽ + /// ȡ + /// + ASURA_ABSTRACT class DecodedData + { + public: + + /// + /// ڴйdataԷһ߳棬Դϵͳء + /// + DecodedData(const DataBuffer& databuffer); + + virtual ~DecodedData(); + + protected: + + /// + /// ڴеݡ + /// + virtual void Decode(const DataBuffer& buffer) = 0; + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/file.cpp b/source/libs/asura-lib-utils/io/file.cpp new file mode 100644 index 0000000..0ff8c90 --- /dev/null +++ b/source/libs/asura-lib-utils/io/file.cpp @@ -0,0 +1,292 @@ +#include <physfs/physfs.h> + +#include <asura-lib-utils/exceptions/exception.h> + +#include "file.h" + +namespace AsuraEngine +{ + namespace IO + { + + File::File(const std::string& filename) + : mFileName(filename) + , mFileHandle(nullptr) + , mMode(FILE_MODE_CLOSED) + , mBufferMode(BUFFER_MODE_NONE) + , mBufferSize(0) + { + size_t dot = filename.rfind('.'); + if (dot != std::string::npos) + { + mExtension = filename.substr(dot + 1); + mName = filename.substr(0, dot); + } + else + mName = filename; + } + + File::~File() + { + if (mMode != FILE_MODE_CLOSED) + Close(); + } + + bool File::Open(FileMode mode) + { + if (!PHYSFS_isInit()) + throw Exception("Physfs is NOT initialized."); + + if (mode == FILE_MODE_CLOSED) + return false; + + if (mode == FILE_MODE_READ && !PHYSFS_exists(mFileName.c_str())) + throw Exception("Could NOT open file %s. Does not exist.", mFileName.c_str()); + + if (mode == FILE_MODE_APPEND || mode == FILE_MODE_WRITE) + { + if (!PHYSFS_getWriteDir()) + { + throw Exception("Could NOT set write directory."); + } + } + + // Ѿ֮ǰͲٴµhandle + if (mFileHandle != nullptr) + return true; + + PHYSFS_getLastErrorCode(); + + PHYSFS_File* handle = nullptr; + + switch (mode) + { + case FILE_MODE_READ: + handle = PHYSFS_openRead(mFileName.c_str()); + break; + case FILE_MODE_APPEND: + handle = PHYSFS_openAppend(mFileName.c_str()); + break; + case FILE_MODE_WRITE: + handle = PHYSFS_openWrite(mFileName.c_str()); + break; + } + + if (handle == nullptr) + { + const char *err = PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()); + if (err == nullptr) + err = "unknown error"; + throw Exception("Could not open file %s (%s)", mFileName.c_str(), err); + } + + mFileHandle = handle; + mMode = mode; + + if (mFileHandle && !SetBuffer(mBufferMode,mBufferSize)) + { + mBufferMode = BUFFER_MODE_NONE; + mBufferSize = 0; + } + + return mFileHandle != nullptr; + } + + bool File::Close() + { + if (mFileHandle == nullptr || !PHYSFS_close(mFileHandle)) + return false; + mMode = FILE_MODE_CLOSED; + mFileHandle = nullptr; + return true; + } + + bool File::IsOpen() + { + return mMode != FILE_MODE_CLOSED && mFileHandle != nullptr; + } + + size_t File::GetSize() + { + if (mFileHandle == nullptr) + { + Open(FILE_MODE_READ); + size_t size = PHYSFS_fileLength(mFileHandle); + Close(); + return size; + } + return PHYSFS_fileLength(mFileHandle); + } + + size_t File::Read(ASURA_OUT DataBuffer* dst, size_t length) + { + ASSERT(dst); + + if (dst->GetSize() < length) + throw Exception("Data buffer is too small compares to read length."); + + if (!mFileHandle || mMode != FILE_MODE_READ) + throw Exception("File \"%s\" is not opened for reading", mFileName); + + size_t max = PHYSFS_fileLength(mFileHandle); + length = (length > max) ? max : length; + + if (length < 0) + throw Exception("Invalid read size."); + + dst->Lock(); + size_t size = PHYSFS_readBytes(mFileHandle, dst->GetData(), length); + dst->Unlock(); + return size; + } + + size_t File::ReadAll(ASURA_OUT DataBuffer* dst) + { + ASSERT(dst); + + if (!mFileHandle || mMode != FILE_MODE_READ) + throw Exception("File \"%s\" is not opened for reading", mFileName); + + size_t length = PHYSFS_fileLength(mFileHandle); + + if (dst->GetSize() < length) + throw Exception("Data buffer is too small compares to file length."); + + dst->Lock(); + size_t size = PHYSFS_readBytes(mFileHandle, dst->GetData(), length); + dst->Unlock(); + return size; + } + +#ifdef ASURA_WINDOWS + inline bool test_eof(File *that, PHYSFS_File *) + { + int64 pos = that->Tell(); + int64 size = that->GetSize(); + return pos == -1 || size == -1 || pos >= size; + } +#else + inline bool test_eof(File *, PHYSFS_File *file) + { + return PHYSFS_eof(file); + } +#endif + + bool File::IsEOF() + { + return mFileHandle == nullptr || test_eof(this, mFileHandle); + } + + size_t File::Tell() + { + if (!mFileHandle) + return - 1; + + return PHYSFS_tell(mFileHandle); + } + + bool File::Seek(size_t pos) + { + return mFileHandle != nullptr && PHYSFS_seek(mFileHandle, pos) != 0; + } + + bool File::Write(ASURA_REF DataBuffer* src) + { + if (!mFileHandle || (mMode != FILE_MODE_APPEND && mMode != FILE_MODE_WRITE)) + throw Exception("File is not opened for writing."); + + byte* data = src->GetData(); + int size = src->GetSize(); + + if (size < 0) + throw Exception("Invalid write size."); + + size_t written = PHYSFS_writeBytes(mFileHandle, data, size); + + if (written != src->GetSize()) + return false; + + // л + if (mBufferSize == BUFFER_MODE_LINE && mBufferSize > size) + { + if (memchr(data, '\n', size) != nullptr) + Flush(); + } + + return true; + } + + bool File::Flush() + { + if (!mFileHandle || (mMode != FILE_MODE_WRITE && mMode != FILE_MODE_APPEND)) + throw Exception("File is not opened for writing."); + + return PHYSFS_flush(mFileHandle) != 0; + } + + bool File::SetBuffer(BufferMode mode, size_t size) + { + if (size < 0) + return false; + + // If the file isn't open, we'll make sure the buffer values are set in + // File::open. + if (!IsOpen()) + { + mBufferMode = mode; + mBufferSize = size; + return true; + } + + int ret = 1; + + switch (mode) + { + case BUFFER_MODE_NONE: + default: + ret = PHYSFS_setBuffer(mFileHandle, 0); + size = 0; + break; + case BUFFER_MODE_LINE: + case BUFFER_MODE_FULL: + ret = PHYSFS_setBuffer(mFileHandle, size); + break; + } + + if (ret == 0) + return false; + + mBufferMode = mode; + mBufferSize = size; + + return true; + } + + File::BufferMode File::GetBuffer(ASURA_OUT size_t& size) + { + size = mBufferSize; + return mBufferMode; + } + + const std::string& File::GetFileName() + { + return mFileName; + } + + const std::string& File::GetName() + { + return mName; + } + + const std::string& File::GetExtension() + { + return mExtension; + } + + File::FileMode File::GetMode() + { + return mMode; + } + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/file.h b/source/libs/asura-lib-utils/io/file.h new file mode 100644 index 0000000..56077e0 --- /dev/null +++ b/source/libs/asura-lib-utils/io/file.h @@ -0,0 +1,146 @@ +#ifndef __ASURA_ENGINE_FILE_H__ +#define __ASURA_ENGINE_FILE_H__ + +#include "physfs/physfs.h" + +#include "../scripting/portable.hpp" +#include "../threading/thread.h" + +#include "file_data.h" + +namespace AsuraEngine +{ + namespace IO + { + + /// + /// ʽļָд㡢Сʹȡʱʹñ࣬ʹFilesystem.read()ֱӶȡļȫ + /// ݣһFileData + /// + class File ASURA_FINAL + : public AEScripting::Portable<File> + { + public: + + LUAX_DECL_FACTORY(File); + + /// + /// ļдģʽ + /// + enum FileMode + { + FILE_MODE_CLOSED, + FILE_MODE_READ, + FILE_MODE_WRITE, + FILE_MODE_APPEND, + }; + + /// + /// ļдʱΪ + /// + enum BufferMode + { + BUFFER_MODE_NONE, ///< ʹû壬дļ + BUFFER_MODE_LINE, ///< л壬зߴﵽСʱдļ + BUFFER_MODE_FULL, ///< ȫ壬ʱдļ + }; + + File(const std::string& filename); + ~File(); + + bool Open(FileMode mode); + bool Close(); + bool IsOpen(); + FileMode GetMode(); + size_t GetSize(); + + /// + /// ȡdata bufferض + /// + size_t Read(ASURA_OUT DataBuffer* dst, size_t length); + size_t ReadAll(ASURA_OUT DataBuffer* dst); + size_t ReadAsync(ASURA_OUT DataBuffer* dst); + + /// + /// Ƿļβ + /// + bool IsEOF(); + + /// + /// data bufferед룬Ƿɹ + /// + bool Write(ASURA_REF DataBuffer* src); + + /// + /// 첽дļдļtaskthreadĶС + /// + bool WriteAsync(ASURA_REF DataBuffer* src, AEThreading::Thread* thread); + + /// + /// ˻壬ǿջдļ + /// + bool Flush(); + + /// + /// صǰдλ + /// + size_t Tell(); + + /// + /// Ӧλ + /// + bool Seek(size_t pos); + + /// + /// ûСģʽ + /// + bool SetBuffer(BufferMode mode, size_t size); + + /// + /// ȡСģʽ + /// + BufferMode GetBuffer(ASURA_OUT size_t& size); + + const std::string& GetFileName(); + const std::string& GetName(); + const std::string& GetExtension(); + + private: + + PHYSFS_File* mFileHandle; ///< physfs ļ + std::string mFileName; ///< ļ + std::string mExtension; ///< չ + std::string mName; ///< չļ + FileMode mMode; ///< ļģʽ + BufferMode mBufferMode; ///< д뻺ģʽ + size_t mBufferSize; ///< д뻺С + + LUAX_DECL_ENUM(FileMode); + LUAX_DECL_ENUM(BufferMode); + + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_Open); + LUAX_DECL_METHOD(_Close); + LUAX_DECL_METHOD(_IsOpen); + LUAX_DECL_METHOD(_GetMode); + LUAX_DECL_METHOD(_GetSize); + LUAX_DECL_METHOD(_Read); + LUAX_DECL_METHOD(_Write); + LUAX_DECL_METHOD(_ReadAsync); + LUAX_DECL_METHOD(_WriteAsync); + LUAX_DECL_METHOD(_IsEOF); + LUAX_DECL_METHOD(_Flush); + LUAX_DECL_METHOD(_Tell); + LUAX_DECL_METHOD(_Seek); + LUAX_DECL_METHOD(_SetBuffer); + LUAX_DECL_METHOD(_GetBuffer); + LUAX_DECL_METHOD(_GetFileName); + LUAX_DECL_METHOD(_GetExtension); + LUAX_DECL_METHOD(_GetName); + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/file_data.cpp b/source/libs/asura-lib-utils/io/file_data.cpp new file mode 100644 index 0000000..92333cf --- /dev/null +++ b/source/libs/asura-lib-utils/io/file_data.cpp @@ -0,0 +1,52 @@ +#include "file_data.h" + +namespace AsuraEngine +{ + namespace IO + { + + FileData::FileData(const std::string& filename) + : mData(nullptr) + , mFileName(filename) + { + size_t dot = filename.rfind('.'); + if (dot != std::string::npos) + { + mExtension = filename.substr(dot + 1); + mName = filename.substr(0, dot); + } + else + mName = filename; + } + + FileData::~FileData() + { + } + + const std::string& FileData::GetFileName() + { + return mFileName; + } + + const std::string& FileData::GetExtension() + { + return mExtension; + } + + const std::string& FileData::GetName() + { + return mName; + } + + void FileData::BindData(ASURA_MOVE DataBuffer* buffer) + { + mData = buffer; + } + + DataBuffer* FileData::GetDataBuffer() + { + return mData; + } + + } +} diff --git a/source/libs/asura-lib-utils/io/file_data.h b/source/libs/asura-lib-utils/io/file_data.h new file mode 100644 index 0000000..9aa0e3b --- /dev/null +++ b/source/libs/asura-lib-utils/io/file_data.h @@ -0,0 +1,69 @@ +#ifndef __ASURA_ENGINE_FILE_DATA_H__ +#define __ASURA_ENGINE_FILE_DATA_H__ + +#include <string> + +#include <asura-lib-utils/scripting/portable.hpp> + +#include "data_buffer.h" + +namespace AsuraEngine +{ + namespace IO + { + + class Filesystem; + + /// + /// filesystemֱӶȡļʱFileDataļݺϢFilesystem + /// + class FileData ASURA_FINAL + : public AEScripting::Portable<FileData> + { + public: + + LUAX_DECL_FACTORY(FileData); + + ~FileData(); + + /// + /// ļݣͨDatabufferݺʹСڲӿڶData bufferΪҲdata buffer + /// + DataBuffer* GetDataBuffer(); + + const std::string& GetFileName(); + const std::string& GetExtension(); + const std::string& GetName(); + + private: + + friend class Filesystem; + + FileData(const std::string& name); + + /// + /// data buffer + /// + void BindData(ASURA_MOVE DataBuffer* buffer); + + /// + /// Data bufferfiledataʱ٣luaüΪ0ʱluaGC١mDataʱһԱá + /// + ASURA_REF DataBuffer* mData; + Luax::LuaxMemberRef mDataRef; + + std::string mFileName; ///< չļ + std::string mExtension; ///< չ + std::string mName; ///< ͺļ + + LUAX_DECL_METHOD(_GetDataBuffer); + LUAX_DECL_METHOD(_GetFileName); + LUAX_DECL_METHOD(_GetExtension); + LUAX_DECL_METHOD(_GetName); + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/file_system.cpp b/source/libs/asura-lib-utils/io/file_system.cpp new file mode 100644 index 0000000..20f3cb2 --- /dev/null +++ b/source/libs/asura-lib-utils/io/file_system.cpp @@ -0,0 +1,198 @@ +#include <physfs/physfs.h> + +#include "../exceptions/exception.h" + +#include "file.h" +#include "file_data.h" +#include "file_system.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace IO + { + +#ifdef ASURA_WINDOWS + #include <windows.h> + #include <direct.h> +#else + #include <sys/param.h> + #include <unistd.h> +#endif + + Filesystem::~Filesystem() + { + if (mInited) //PHYSFS_isInit + PHYSFS_deinit(); + } + + void Filesystem::Init(const char* arg0) + { + if (!PHYSFS_init(arg0)) + throw Exception("Failed to initialize filesystem: %s", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); + + mInited = true; + } + + bool Filesystem::Mount(const std::string& locpath, const std::string& montpoint/* = "/"*/, bool prepend /*= false*/) + { + if (!mInited) + return false; + + return PHYSFS_mount(locpath.c_str(), montpoint.c_str(), !prepend); + } + + bool Filesystem::Mount(DataBuffer* db, const std::string& archivename, const std::string& mountpoint /*= "/"*/, bool prepend /*= false*/) + { + if (!mInited) + return false; + if (PHYSFS_mountMemory(db->GetData(), db->GetSize(), nullptr, archivename.c_str(), mountpoint.c_str(), !prepend)) + { + mMountData[archivename] = db; + return true; + } + return false; + } + + bool Filesystem::Unmount(const std::string& locpath) + { + if (!mInited) + return false; + + // ǹ鵵ӳɾ + auto datait = mMountData.find(locpath); + if (datait != mMountData.end() && PHYSFS_unmount(locpath.c_str()) != 0) + { + mMountData.erase(datait); + return true; + } + + return PHYSFS_unmount(locpath.c_str()); + } + + bool Filesystem::Unmount(DataBuffer* db) + { + for (const auto& dp : mMountData) + { + if (dp.second == db) + { + std::string archive = dp.first; + return Unmount(archive); + } + } + } + + bool Filesystem::GetMountPoint(const std::string& locpath, ASURA_OUT std::string& mountpoint) + { + if (!mInited) + return false; + const char* point = PHYSFS_getMountPoint(locpath.c_str()); + if (point != nullptr) + { + mountpoint = point; + return true; + } + return false; + } + + void Filesystem::SetWriteDirectory(const std::string locpath) + { + if (!mInited) + return; + if (!PHYSFS_setWriteDir(locpath.c_str())) + throw Exception("Failed to set write directory %s", locpath.c_str()); + } + + std::string Filesystem::GetWriteDirectory() + { + return PHYSFS_getWriteDir(); + } + + File* Filesystem::NewFile(const std::string& name) + { + return new File(name); + } + + bool Filesystem::NewDirectory(const std::string& path) + { + if (!mInited) + return false; + if (!PHYSFS_getWriteDir()) + return false; + if (!PHYSFS_mkdir(path.c_str())) + return false; + return true; + } + + bool Filesystem::Write(const std::string& name, ASURA_REF DataBuffer* buffer) + { + File file(name); + file.Open(File::FILE_MODE_WRITE); + if (!file.Write(buffer)) + throw Exception("Data could not be written."); + } + + bool Filesystem::Append(const std::string& name, ASURA_REF DataBuffer* buffer) + { + File file(name); + file.Open(File::FILE_MODE_APPEND); + if (!file.Write(buffer)) + throw Exception("Data could not be append."); + } + + FileData* Filesystem::Read(const std::string& name) + { + File file = File(name); + file.Open(File::FILE_MODE_READ); + int size = file.GetSize(); + DataBuffer* db = new DataBuffer(size); + if (db) + { + file.ReadAll(db); + FileData* fd = new FileData(name); + fd->BindData(db); + return fd; + } + return nullptr; + } + + bool Filesystem::Remove(const std::string& path) + { + if (!mInited) + return false; + if (PHYSFS_getWriteDir() == 0) + return false; + + if (!PHYSFS_delete(path.c_str())) + return false; + + return true; + } + + bool Filesystem::GetFileInfo(const std::string& filepath, ASURA_OUT FileInfo* info) + { + if (!mInited) + return false; + + PHYSFS_Stat stat = {}; + if (!PHYSFS_stat(filepath.c_str(), &stat)) + return false; + + info->size = (int64)stat.filesize; + info->modtime = (int64)stat.modtime; + + if (stat.filetype == PHYSFS_FILETYPE_REGULAR) + info->type = FILE_TYPE_FILE; + else if (stat.filetype == PHYSFS_FILETYPE_DIRECTORY) + info->type = FILE_TYPE_DIRECTORY; + else if (stat.filetype == PHYSFS_FILETYPE_SYMLINK) + info->type = FILE_TYPE_SYMLINK; + else + info->type = FILE_TYPE_OTHER; + + return true; + } + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/file_system.h b/source/libs/asura-lib-utils/io/file_system.h new file mode 100644 index 0000000..849cbb6 --- /dev/null +++ b/source/libs/asura-lib-utils/io/file_system.h @@ -0,0 +1,112 @@ +#ifndef __ASURA_ENGINE_FILESYSTEM_H__ +#define __ASURA_ENGINE_FILESYSTEM_H__ + +#include <map> +#include <string> + +#include "../scripting/portable.hpp" +#include "../singleton.hpp" +#include "../type.h" + +#include "file_data.h" +#include "file.h" + +namespace AsuraEngine +{ + namespace IO + { + + enum FileType + { + FILE_TYPE_FILE, ///< ļ + FILE_TYPE_DIRECTORY, ///< ļ + FILE_TYPE_SYMLINK, ///< + FILE_TYPE_OTHER, ///< + }; + + struct FileInfo + { + int64 size; + int64 modtime; + FileType type; + }; + + /// + /// Դء洢ԴָĿ¼ȡ۱༭ʱҪƷʵĻƣûIJϷĿ¼ + /// £file systemµġFilesystemʱͱ༭õ࣬AssetDatabaseԴ࣬framework + /// ʵ֣дFilesystemʵ֣AssetDatabaseṩļݴӦԴķ + /// + class Filesystem ASURA_FINAL + : public Singleton<Filesystem> + , public AEScripting::Portable<Filesystem> + { + public: + + LUAX_DECL_SINGLETON(Filesystem); + + ~Filesystem(); + + void Init(const char* arg0); + + /// + /// ǰִļļ + /// + std::string GetWorkingDirectory(); + + bool Mount(const std::string& locpath, const std::string& montpoint = "/", bool prepend = false); + bool Mount(DataBuffer* db, const std::string& archivename, const std::string& mountpoint = "/", bool prepend = false); + + bool Unmount(const std::string& locpath); + bool Unmount(DataBuffer* db); + + bool GetMountPoint(const std::string& locpath, ASURA_OUT std::string& mountpoint); + + void SetWriteDirectory(const std::string locpath); + std::string GetWriteDirectory(); + File* NewFile(const std::string& name); + bool NewDirectory(const std::string& path); + bool Write(const std::string& path, ASURA_REF DataBuffer* buffer); + bool Append(const std::string& path, ASURA_REF DataBuffer* buffer); + bool Remove(const std::string& path); + + FileData* Read(const std::string& path); + bool GetFileInfo(const std::string& path, ASURA_OUT FileInfo* info); + + bool GetDirectoryItems(const std::string& path, ASURA_OUT std::vector<std::string>& items) { return false; }; + + private: + + typedef std::map<std::string, DataBuffer*> MountDataMap; + + bool mInited; ///< Ƿʼɹ + std::string mCwd; ///< ǰִļĹĿ¼ + MountDataMap mMountData; ///< ·ѹĵӳ + + LUAX_DECL_METHOD(_Init); + LUAX_DECL_METHOD(_Mount); + LUAX_DECL_METHOD(_Unmount); + LUAX_DECL_METHOD(_GetMountPoint); + + LUAX_DECL_METHOD(_SetWriteDirectory); + LUAX_DECL_METHOD(_GetWriteDirectory); + LUAX_DECL_METHOD(_CreateFile); + LUAX_DECL_METHOD(_CreateDirectory); + + LUAX_DECL_METHOD(_Write); + LUAX_DECL_METHOD(_Append); + LUAX_DECL_METHOD(_Remove); + + LUAX_DECL_METHOD(_Read); + + LUAX_DECL_METHOD(_GetFileInfo); + + LUAX_DECL_METHOD(_GetDirectoryItems); + + }; + + } +} + +namespace AEIO = AsuraEngine::IO; + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/io_batch_task.cpp b/source/libs/asura-lib-utils/io/io_batch_task.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-utils/io/io_batch_task.cpp diff --git a/source/libs/asura-lib-utils/io/io_batch_task.h b/source/libs/asura-lib-utils/io/io_batch_task.h new file mode 100644 index 0000000..c0be921 --- /dev/null +++ b/source/libs/asura-lib-utils/io/io_batch_task.h @@ -0,0 +1,31 @@ +#ifndef __ASURA_IO_BATCH_TASK_H__ +#define __ASURA_IO_BATCH_TASK_H__ + +#include "io_task.h" + +namespace AsuraEngine +{ + namespace IO + { + + /// + /// дһύһtableδؽ + /// + class IOBatchTask ASURA_FINAL : public AEThreading::Task + { + public: + + private: + + /// + /// ÿһĽṹ£ + /// { path = "", } + /// + Luax::LuaxMemberRef mTasks; + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/io_task.cpp b/source/libs/asura-lib-utils/io/io_task.cpp new file mode 100644 index 0000000..361b9c5 --- /dev/null +++ b/source/libs/asura-lib-utils/io/io_task.cpp @@ -0,0 +1,55 @@ +#include "file_system.h" +#include "io_task.h" + +#include <iostream> + +using namespace AEScripting; +using namespace Luax; + +namespace AsuraEngine +{ + namespace IO + { + + IOTask::IOTask(const std::string& path, DataBuffer* buffer, IOTaskType type) + : mPath(path) + , mBuffer(buffer) + { + } + + IOTask::~IOTask() + { + } + + bool IOTask::Execute() + { + File file(mPath); + if (mType == IOTASK_TYPE_WRITE) + { + + } + // pathȡݱmBuffer + else if (mType == IOTASK_TYPE_READ) + { + file.Open(File::FILE_MODE_READ); + file.ReadAll(mBuffer); + file.Close(); + } + return true; + } + + void IOTask::Invoke(lua_State* invokeThreaad) + { + if (mCallback) + { + LuaxScopedState state(invokeThreaad); + if (PushLuaxMemberRef(state, mCallback)) + { + PushLuaxMemberRef(state, mBufferRef); + state.Call(1, 0); + } + } + } + + } +} diff --git a/source/libs/asura-lib-utils/io/io_task.h b/source/libs/asura-lib-utils/io/io_task.h new file mode 100644 index 0000000..8f04142 --- /dev/null +++ b/source/libs/asura-lib-utils/io/io_task.h @@ -0,0 +1,57 @@ +#ifndef __ASURA_IO_TASK_H__ +#define __ASURA_IO_TASK_H__ + +#include <string> + +#include "../scripting/portable.hpp" +#include "../threading/task.h" + +#include "data_buffer.h" + +namespace AsuraEngine +{ + namespace IO + { + + enum IOTaskType + { + IOTASK_TYPE_READ, + IOTASK_TYPE_WRITE, + IOTASK_TYPE_APPEND, + }; + + /// + /// ȡļ + /// + class IOTask ASURA_FINAL + : public AEThreading::Task + , public AEScripting::Portable<IOTask> + { + public: + + LUAX_DECL_FACTORY(IOTask); + + IOTask(const std::string& path, DataBuffer* buffer, IOTaskType type); + ~IOTask(); + + bool Execute() override ; + void Invoke(lua_State* invokeThreaad) override; + + private: + + LUAX_DECL_ENUM(IOTaskType); + + LUAX_DECL_METHOD(_New); + + std::string mPath; + IOTaskType mType; + + ASURA_REF DataBuffer* mBuffer; + Luax::LuaxMemberRef mBufferRef; + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/io/reloadable.h b/source/libs/asura-lib-utils/io/reloadable.h new file mode 100644 index 0000000..22a721c --- /dev/null +++ b/source/libs/asura-lib-utils/io/reloadable.h @@ -0,0 +1,29 @@ +#ifndef __ASURA_ENGINE_RELOADABLE_H__ +#define __ASURA_ENGINE_RELOADABLE_H__ + +#include "../scripting/portable.hpp" + +namespace AsuraEngine +{ + namespace IO + { + + /// + /// ¹ݽṹͼƬƵ֣ⲿݿֱӹڱ༭¹ڲıhandleԴ + /// + ASURA_ABSTRACT class Reloadable + { + public: + Reloadable(); + virtual ~Reloadable(); + + // ̳ReloadableҪṩһload + + }; + + } +} + +namespace AEIO = AsuraEngine::IO; + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/manager.hpp b/source/libs/asura-lib-utils/manager.hpp new file mode 100644 index 0000000..7b4e272 --- /dev/null +++ b/source/libs/asura-lib-utils/manager.hpp @@ -0,0 +1,14 @@ +#ifndef __ASURA_ENGINE_MANAGER_H__ +#define __ASURA_ENGINE_MANAGER_H__ + +namespace AsuraEngine +{ + + class Manager + { + + }; + +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/math/curve.cpp b/source/libs/asura-lib-utils/math/curve.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-utils/math/curve.cpp diff --git a/source/libs/asura-lib-utils/math/curve.h b/source/libs/asura-lib-utils/math/curve.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-utils/math/curve.h diff --git a/source/libs/asura-lib-utils/math/functions.cpp b/source/libs/asura-lib-utils/math/functions.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-utils/math/functions.cpp diff --git a/source/libs/asura-lib-utils/math/functions.h b/source/libs/asura-lib-utils/math/functions.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-utils/math/functions.h diff --git a/source/libs/asura-lib-utils/math/matrix44.cpp b/source/libs/asura-lib-utils/math/matrix44.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-utils/math/matrix44.cpp diff --git a/source/libs/asura-lib-utils/math/matrix44.h b/source/libs/asura-lib-utils/math/matrix44.h new file mode 100644 index 0000000..4ab3c0b --- /dev/null +++ b/source/libs/asura-lib-utils/math/matrix44.h @@ -0,0 +1,24 @@ +#ifndef __ASURA_ENGINE_MATRIX44_H__ +#define __ASURA_ENGINE_MATRIX44_H__ + +namespace AsuraEngine +{ + namespace Math + { + + /// + /// 4x4 + /// + class Matrix44 + { + public: + + private: + + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/math/quaternion.cpp b/source/libs/asura-lib-utils/math/quaternion.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-utils/math/quaternion.cpp diff --git a/source/libs/asura-lib-utils/math/quaternion.h b/source/libs/asura-lib-utils/math/quaternion.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-utils/math/quaternion.h diff --git a/source/libs/asura-lib-utils/math/ranged_value.cpp b/source/libs/asura-lib-utils/math/ranged_value.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-utils/math/ranged_value.cpp diff --git a/source/libs/asura-lib-utils/math/ranged_value.h b/source/libs/asura-lib-utils/math/ranged_value.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-utils/math/ranged_value.h diff --git a/source/libs/asura-lib-utils/math/rect.hpp b/source/libs/asura-lib-utils/math/rect.hpp new file mode 100644 index 0000000..1751634 --- /dev/null +++ b/source/libs/asura-lib-utils/math/rect.hpp @@ -0,0 +1,47 @@ +#ifndef __ASURA_ENGINE_RECT_H__ +#define __ASURA_ENGINE_RECT_H__ + +namespace AsuraEngine +{ + namespace Math + { + + template<typename T> + struct Rect + { + public: + Rect(); + ~Rect(T x, T y, T w, T h); + + /// + /// x,yǷrectڡ + /// + bool Contain(T x, T y); + + /// + /// Ƿཻཻľ + /// + bool Intersect(const Rect& src, Rect& intersection); + + /// + /// Ƿཻཻľ + /// + static bool Intersect(const Rect<T>& src1, const Rect<T>& src2, Rect<T>& intersection); + + T x, y, w, h; + }; + +#include "Rect.inl" + + // Define the most common types + typedef Rect<int> Recti; + typedef Rect<unsigned int> Rectu; + typedef Rect<float> Rectf; + typedef Rect<long> Reftl; + + } +} + +namespace AEMath = AsuraEngine::Math; + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/math/rect.inl b/source/libs/asura-lib-utils/math/rect.inl new file mode 100644 index 0000000..891a3f8 --- /dev/null +++ b/source/libs/asura-lib-utils/math/rect.inl @@ -0,0 +1,19 @@ +template <typename T> +inline Rect<T>::Rect() + : x(0) + , y(0) + , w(0) + , h(0) +{ + +} + +template <typename T> +inline Rect<T>::Rect(T X, T Y, T W, T H) + : x(X) + , y(Y) + , w(W) + , h(H) +{ + +} diff --git a/source/libs/asura-lib-utils/math/transform.cpp b/source/libs/asura-lib-utils/math/transform.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-utils/math/transform.cpp diff --git a/source/libs/asura-lib-utils/math/transform.h b/source/libs/asura-lib-utils/math/transform.h new file mode 100644 index 0000000..be4c850 --- /dev/null +++ b/source/libs/asura-lib-utils/math/transform.h @@ -0,0 +1,30 @@ +#ifndef __ASURA_ENGINE_TRANSFORM_H__ +#define __ASURA_ENGINE_TRANSFORM_H__ + +#include "../scripting/portable.hpp" + +namespace AsuraEngine +{ + namespace Math + { + + class Transform + { + public: + + void Set(float x, float y, float sx, float sy, float ox, float oy, float r); + + void LoadIdentity(); + + void Move(float dx = 0, float dy = 0); + void Rotate(float r); + void Scale(float sx, float sy); + + float m[16]; //4x4 matrix + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/math/vector2.hpp b/source/libs/asura-lib-utils/math/vector2.hpp new file mode 100644 index 0000000..df78255 --- /dev/null +++ b/source/libs/asura-lib-utils/math/vector2.hpp @@ -0,0 +1,70 @@ +#ifndef __ASURA_ENGINE_VECTOR2_H__ +#define __ASURA_ENGINE_VECTOR2_H__ + +namespace AsuraEngine +{ + namespace Math + { + template <typename T> + class Vector2 + { + public: + Vector2(); + Vector2(T X, T Y); + + template <typename U> + explicit Vector2(const Vector2<U>& vector); + + Set(T X, T Y); + + T x; ///< X coordinate of the vector + T y; ///< Y coordinate of the vector + }; + + template <typename T> + Vector2<T> operator -(const Vector2<T>& right); + + template <typename T> + Vector2<T>& operator +=(Vector2<T>& left, const Vector2<T>& right); + + template <typename T> + Vector2<T>& operator -=(Vector2<T>& left, const Vector2<T>& right); + + template <typename T> + Vector2<T> operator +(const Vector2<T>& left, const Vector2<T>& right); + + template <typename T> + Vector2<T> operator -(const Vector2<T>& left, const Vector2<T>& right); + + template <typename T> + Vector2<T> operator *(const Vector2<T>& left, T right); + + template <typename T> + Vector2<T> operator *(T left, const Vector2<T>& right); + + template <typename T> + Vector2<T>& operator *=(Vector2<T>& left, T right); + + template <typename T> + Vector2<T> operator /(const Vector2<T>& left, T right); + + template <typename T> + Vector2<T>& operator /=(Vector2<T>& left, T right); + + template <typename T> + bool operator ==(const Vector2<T>& left, const Vector2<T>& right); + + template <typename T> + bool operator !=(const Vector2<T>& left, const Vector2<T>& right); + +#include "Vector2.inl" + + // Define the most common types + typedef Vector2<int> Vector2i; + typedef Vector2<unsigned int> Vector2u; + typedef Vector2<float> Vector2f; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/math/vector2.inl b/source/libs/asura-lib-utils/math/vector2.inl new file mode 100644 index 0000000..9e131a7 --- /dev/null +++ b/source/libs/asura-lib-utils/math/vector2.inl @@ -0,0 +1,114 @@ +template <typename T> +inline Vector2<T>::Vector2() : + x(0), + y(0) +{ + +} + +template <typename T> +inline Vector2<T>::Vector2(T X, T Y) : + x(X), + y(Y) +{ + +} + +template <typename T> +template <typename U> +inline Vector2<T>::Vector2(const Vector2<U>& vector) : + x(static_cast<T>(vector.x)), + y(static_cast<T>(vector.y)) +{ +} + +template <typename T> +inline Vector2<T>::Set(T X, T Y) +{ + x = X; + y = Y; +} + +template <typename T> +inline Vector2<T> operator -(const Vector2<T>& right) +{ + return Vector2<T>(-right.x, -right.y); +} + +template <typename T> +inline Vector2<T>& operator +=(Vector2<T>& left, const Vector2<T>& right) +{ + left.x += right.x; + left.y += right.y; + + return left; +} + +template <typename T> +inline Vector2<T>& operator -=(Vector2<T>& left, const Vector2<T>& right) +{ + left.x -= right.x; + left.y -= right.y; + + return left; +} + +template <typename T> +inline Vector2<T> operator +(const Vector2<T>& left, const Vector2<T>& right) +{ + return Vector2<T>(left.x + right.x, left.y + right.y); +} + +template <typename T> +inline Vector2<T> operator -(const Vector2<T>& left, const Vector2<T>& right) +{ + return Vector2<T>(left.x - right.x, left.y - right.y); +} + +template <typename T> +inline Vector2<T> operator *(const Vector2<T>& left, T right) +{ + return Vector2<T>(left.x * right, left.y * right); +} + +template <typename T> +inline Vector2<T> operator *(T left, const Vector2<T>& right) +{ + return Vector2<T>(right.x * left, right.y * left); +} + +template <typename T> +inline Vector2<T>& operator *=(Vector2<T>& left, T right) +{ + left.x *= right; + left.y *= right; + + return left; +} + +template <typename T> +inline Vector2<T> operator /(const Vector2<T>& left, T right) +{ + return Vector2<T>(left.x / right, left.y / right); +} + +template <typename T> +inline Vector2<T>& operator /=(Vector2<T>& left, T right) +{ + left.x /= right; + left.y /= right; + + return left; +} + +template <typename T> +inline bool operator ==(const Vector2<T>& left, const Vector2<T>& right) +{ + return (left.x == right.x) && (left.y == right.y); +} + +template <typename T> +inline bool operator !=(const Vector2<T>& left, const Vector2<T>& right) +{ + return (left.x != right.x) || (left.y != right.y); +} diff --git a/source/libs/asura-lib-utils/math/vector3.hpp b/source/libs/asura-lib-utils/math/vector3.hpp new file mode 100644 index 0000000..2b23406 --- /dev/null +++ b/source/libs/asura-lib-utils/math/vector3.hpp @@ -0,0 +1,233 @@ +#ifndef __ASURA_ENGINE_VECTOR3_H__ +#define __ASURA_ENGINE_VECTOR3_H__ + +namespace AsuraEngine +{ + namespace Math + { + template <typename T> + class Vector3 + { + public: + + //////////////////////////////////////////////////////////// + /// \brief Default constructor + /// + /// Creates a Vector3(0, 0, 0). + /// + //////////////////////////////////////////////////////////// + Vector3(); + + //////////////////////////////////////////////////////////// + /// \brief Construct the vector from its coordinates + /// + /// \param X X coordinate + /// \param Y Y coordinate + /// \param Z Z coordinate + /// + //////////////////////////////////////////////////////////// + Vector3(T X, T Y, T Z); + + //////////////////////////////////////////////////////////// + /// \brief Construct the vector from another type of vector + /// + /// This constructor doesn't replace the copy constructor, + /// it's called only when U != T. + /// A call to this constructor will fail to compile if U + /// is not convertible to T. + /// + /// \param vector Vector to convert + /// + //////////////////////////////////////////////////////////// + template <typename U> + explicit Vector3(const Vector3<U>& vector); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + T x; ///< X coordinate of the vector + T y; ///< Y coordinate of the vector + T z; ///< Z coordinate of the vector + }; + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of unary operator - + /// + /// \param left Vector to negate + /// + /// \return Memberwise opposite of the vector + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector3<T> operator -(const Vector3<T>& left); + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of binary operator += + /// + /// This operator performs a memberwise addition of both vectors, + /// and assigns the result to \a left. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return Reference to \a left + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector3<T>& operator +=(Vector3<T>& left, const Vector3<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of binary operator -= + /// + /// This operator performs a memberwise subtraction of both vectors, + /// and assigns the result to \a left. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return Reference to \a left + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector3<T>& operator -=(Vector3<T>& left, const Vector3<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of binary operator + + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return Memberwise addition of both vectors + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector3<T> operator +(const Vector3<T>& left, const Vector3<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of binary operator - + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return Memberwise subtraction of both vectors + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector3<T> operator -(const Vector3<T>& left, const Vector3<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of binary operator * + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a scalar value) + /// + /// \return Memberwise multiplication by \a right + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector3<T> operator *(const Vector3<T>& left, T right); + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of binary operator * + /// + /// \param left Left operand (a scalar value) + /// \param right Right operand (a vector) + /// + /// \return Memberwise multiplication by \a left + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector3<T> operator *(T left, const Vector3<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of binary operator *= + /// + /// This operator performs a memberwise multiplication by \a right, + /// and assigns the result to \a left. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a scalar value) + /// + /// \return Reference to \a left + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector3<T>& operator *=(Vector3<T>& left, T right); + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of binary operator / + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a scalar value) + /// + /// \return Memberwise division by \a right + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector3<T> operator /(const Vector3<T>& left, T right); + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of binary operator /= + /// + /// This operator performs a memberwise division by \a right, + /// and assigns the result to \a left. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a scalar value) + /// + /// \return Reference to \a left + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector3<T>& operator /=(Vector3<T>& left, T right); + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of binary operator == + /// + /// This operator compares strict equality between two vectors. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return True if \a left is equal to \a right + /// + //////////////////////////////////////////////////////////// + template <typename T> + bool operator ==(const Vector3<T>& left, const Vector3<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector3 + /// \brief Overload of binary operator != + /// + /// This operator compares strict difference between two vectors. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return True if \a left is not equal to \a right + /// + //////////////////////////////////////////////////////////// + template <typename T> + bool operator !=(const Vector3<T>& left, const Vector3<T>& right); + +#include "Vector3.inl" + + // Define the most common types + typedef Vector3<int> Vector3i; + typedef Vector3<float> Vector3f; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/math/vector3.inl b/source/libs/asura-lib-utils/math/vector3.inl new file mode 100644 index 0000000..3a2aa93 --- /dev/null +++ b/source/libs/asura-lib-utils/math/vector3.inl @@ -0,0 +1,145 @@ + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector3<T>::Vector3() : + x(0), + y(0), + z(0) +{ + +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector3<T>::Vector3(T X, T Y, T Z) : + x(X), + y(Y), + z(Z) +{ + +} + + +//////////////////////////////////////////////////////////// +template <typename T> +template <typename U> +inline Vector3<T>::Vector3(const Vector3<U>& vector) : + x(static_cast<T>(vector.x)), + y(static_cast<T>(vector.y)), + z(static_cast<T>(vector.z)) +{ +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector3<T> operator -(const Vector3<T>& left) +{ + return Vector3<T>(-left.x, -left.y, -left.z); +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector3<T>& operator +=(Vector3<T>& left, const Vector3<T>& right) +{ + left.x += right.x; + left.y += right.y; + left.z += right.z; + + return left; +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector3<T>& operator -=(Vector3<T>& left, const Vector3<T>& right) +{ + left.x -= right.x; + left.y -= right.y; + left.z -= right.z; + + return left; +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector3<T> operator +(const Vector3<T>& left, const Vector3<T>& right) +{ + return Vector3<T>(left.x + right.x, left.y + right.y, left.z + right.z); +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector3<T> operator -(const Vector3<T>& left, const Vector3<T>& right) +{ + return Vector3<T>(left.x - right.x, left.y - right.y, left.z - right.z); +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector3<T> operator *(const Vector3<T>& left, T right) +{ + return Vector3<T>(left.x * right, left.y * right, left.z * right); +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector3<T> operator *(T left, const Vector3<T>& right) +{ + return Vector3<T>(right.x * left, right.y * left, right.z * left); +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector3<T>& operator *=(Vector3<T>& left, T right) +{ + left.x *= right; + left.y *= right; + left.z *= right; + + return left; +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector3<T> operator /(const Vector3<T>& left, T right) +{ + return Vector3<T>(left.x / right, left.y / right, left.z / right); +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector3<T>& operator /=(Vector3<T>& left, T right) +{ + left.x /= right; + left.y /= right; + left.z /= right; + + return left; +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline bool operator ==(const Vector3<T>& left, const Vector3<T>& right) +{ + return (left.x == right.x) && (left.y == right.y) && (left.z == right.z); +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline bool operator !=(const Vector3<T>& left, const Vector3<T>& right) +{ + return (left.x != right.x) || (left.y != right.y) || (left.z != right.z); +} diff --git a/source/libs/asura-lib-utils/math/vector4.h b/source/libs/asura-lib-utils/math/vector4.h new file mode 100644 index 0000000..13a9d8a --- /dev/null +++ b/source/libs/asura-lib-utils/math/vector4.h @@ -0,0 +1,234 @@ +#ifndef __ASURA_ENGINE_VECTOR4_H__ +#define __ASURA_ENGINE_VECTOR4_H__ + +namespace AsuraEngine +{ + namespace Math + { + template <typename T> + class Vector4 + { + public: + + //////////////////////////////////////////////////////////// + /// \brief Default constructor + /// + /// Creates a Vector4(0, 0, 0). + /// + //////////////////////////////////////////////////////////// + Vector4(); + + //////////////////////////////////////////////////////////// + /// \brief Construct the vector from its coordinates + /// + /// \param X X coordinate + /// \param Y Y coordinate + /// \param Z Z coordinate + /// + //////////////////////////////////////////////////////////// + Vector4(T X, T Y, T Z, T W); + + //////////////////////////////////////////////////////////// + /// \brief Construct the vector from another type of vector + /// + /// This constructor doesn't replace the copy constructor, + /// it's called only when U != T. + /// A call to this constructor will fail to compile if U + /// is not convertible to T. + /// + /// \param vector Vector to convert + /// + //////////////////////////////////////////////////////////// + template <typename U> + explicit Vector4(const Vector4<U>& vector); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + T x; ///< X coordinate of the vector + T y; ///< Y coordinate of the vector + T z; ///< Z coordinate of the vector + T w; ///< W coordinate of the vector + }; + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of unary operator - + /// + /// \param left Vector to negate + /// + /// \return Memberwise opposite of the vector + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector4<T> operator -(const Vector4<T>& left); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator += + /// + /// This operator performs a memberwise addition of both vectors, + /// and assigns the result to \a left. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return Reference to \a left + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector4<T>& operator +=(Vector4<T>& left, const Vector4<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator -= + /// + /// This operator performs a memberwise subtraction of both vectors, + /// and assigns the result to \a left. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return Reference to \a left + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector4<T>& operator -=(Vector4<T>& left, const Vector4<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator + + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return Memberwise addition of both vectors + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector4<T> operator +(const Vector4<T>& left, const Vector4<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator - + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return Memberwise subtraction of both vectors + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector4<T> operator -(const Vector4<T>& left, const Vector4<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator * + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a scalar value) + /// + /// \return Memberwise multiplication by \a right + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector4<T> operator *(const Vector4<T>& left, T right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator * + /// + /// \param left Left operand (a scalar value) + /// \param right Right operand (a vector) + /// + /// \return Memberwise multiplication by \a left + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector4<T> operator *(T left, const Vector4<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator *= + /// + /// This operator performs a memberwise multiplication by \a right, + /// and assigns the result to \a left. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a scalar value) + /// + /// \return Reference to \a left + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector4<T>& operator *=(Vector4<T>& left, T right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator / + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a scalar value) + /// + /// \return Memberwise division by \a right + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector4<T> operator /(const Vector4<T>& left, T right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator /= + /// + /// This operator performs a memberwise division by \a right, + /// and assigns the result to \a left. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a scalar value) + /// + /// \return Reference to \a left + /// + //////////////////////////////////////////////////////////// + template <typename T> + Vector4<T>& operator /=(Vector4<T>& left, T right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator == + /// + /// This operator compares strict equality between two vectors. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return True if \a left is equal to \a right + /// + //////////////////////////////////////////////////////////// + template <typename T> + bool operator ==(const Vector4<T>& left, const Vector4<T>& right); + + //////////////////////////////////////////////////////////// + /// \relates Vector4 + /// \brief Overload of binary operator != + /// + /// This operator compares strict difference between two vectors. + /// + /// \param left Left operand (a vector) + /// \param right Right operand (a vector) + /// + /// \return True if \a left is not equal to \a right + /// + //////////////////////////////////////////////////////////// + template <typename T> + bool operator !=(const Vector4<T>& left, const Vector4<T>& right); + +#include "Vector4.inl" + + // Define the most common types + typedef Vector4<int> Vector4i; + typedef Vector4<float> Vector4f; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/math/vector4.inl b/source/libs/asura-lib-utils/math/vector4.inl new file mode 100644 index 0000000..025bfcc --- /dev/null +++ b/source/libs/asura-lib-utils/math/vector4.inl @@ -0,0 +1,152 @@ + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector4<T>::Vector4() : + x(0), + y(0), + z(0), + w(0) +{ + +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector4<T>::Vector4(T X, T Y, T Z) : + x(X), + y(Y), + z(Z), + w(0) +{ + +} + + +//////////////////////////////////////////////////////////// +template <typename T> +template <typename U> +inline Vector4<T>::Vector4(const Vector4<U>& vector) : + x(static_cast<T>(vector.x)), + y(static_cast<T>(vector.y)), + z(static_cast<T>(vector.z)) + w(static_cast<T>(vector.w)) +{ +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector4<T> operator -(const Vector4<T>& left) +{ + return Vector4<T>(-left.x, -left.y, -left.z, -left.w); +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector4<T>& operator +=(Vector4<T>& left, const Vector4<T>& right) +{ + left.x += right.x; + left.y += right.y; + left.z += right.z; + left.w += right.w; + + return left; +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector4<T>& operator -=(Vector4<T>& left, const Vector4<T>& right) +{ + left.x -= right.x; + left.y -= right.y; + left.z -= right.z; + left.w -= right.w; + + return left; +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector4<T> operator +(const Vector4<T>& left, const Vector4<T>& right) +{ + return Vector4<T>(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w); +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector4<T> operator -(const Vector4<T>& left, const Vector4<T>& right) +{ + return Vector4<T>(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w); +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector4<T> operator *(const Vector4<T>& left, T right) +{ + return Vector4<T>(left.x * right, left.y * right, left.z * right, left.w * right); +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector4<T> operator *(T left, const Vector4<T>& right) +{ + return Vector4<T>(right.x * left, right.y * left, right.z * left, right.w * left); +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector4<T>& operator *=(Vector4<T>& left, T right) +{ + left.x *= right; + left.y *= right; + left.z *= right; + left.w *= right; + + return left; +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector4<T> operator /(const Vector4<T>& left, T right) +{ + return Vector4<T>(left.x / right, left.y / right, left.z / right, left.w / right); +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline Vector4<T>& operator /=(Vector4<T>& left, T right) +{ + left.x /= right; + left.y /= right; + left.z /= right; + left.w /= right; + + return left; +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline bool operator ==(const Vector4<T>& left, const Vector4<T>& right) +{ + return (left.x == right.x) && (left.y == right.y) && (left.z == right.z) && (left.w == right.w); +} + + +//////////////////////////////////////////////////////////// +template <typename T> +inline bool operator !=(const Vector4<T>& left, const Vector4<T>& right) +{ + return (left.x != right.x) || (left.y != right.y) || (left.z != right.z) || (left.w != right.w); +} diff --git a/source/libs/asura-lib-utils/module.h b/source/libs/asura-lib-utils/module.h new file mode 100644 index 0000000..b22c68c --- /dev/null +++ b/source/libs/asura-lib-utils/module.h @@ -0,0 +1,32 @@ +#ifndef __ASURA_MODULE_H__ +#define __ASURA_MODULE_H__ + +#include "type.h" +#include "scripting/portable.hpp" + +namespace AsuraEngine +{ + + /// + /// Asura libs Ҫ̳д࣬Կעᡣģа˳Щģ飬Ȼ˳InitializeFinalizeʼ + /// رЩģ顣 + /// + ASURA_ABSTRACT class Module + { + public: + + /// + /// ʼģ顣 + /// + virtual void Initialize(Luax::LuaxState& state) = 0; + + /// + /// رģ顣 + /// + virtual void Finalize(Luax::LuaxState& state) = 0; + + }; + +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/scripting/lua_env.h b/source/libs/asura-lib-utils/scripting/lua_env.h new file mode 100644 index 0000000..e2fc4fc --- /dev/null +++ b/source/libs/asura-lib-utils/scripting/lua_env.h @@ -0,0 +1,72 @@ +#ifndef __ASURA_LUA_ENV_H__ +#define __ASURA_LUA_ENV_H__ + +extern "C" +{ +#include <Lua51/lua.h> +#include <Lua51/lauxlib.h> +} +#include <Luax/luax.h> + +#include "../singleton.hpp" + +namespace AsuraEngine +{ + namespace Scripting + { + + /// + /// ͨӿڷlua stateAsura˼ǣ߳άһluaӦ + /// Ҫڴlua߽߳ջ + /// + class LuaEnv ASURA_FINAL : public Singleton<LuaEnv> + { + public: + + LuaEnv() : mVM(0) {}; + ~LuaEnv() {}; + + /// + /// ִջ + /// + inline void Init() + { + ASSERT(!mVM); + mVM = new Luax::LuaxVM(); + ASSERT(mVM); + mVM->Setup(); + }; + + inline lua_State* GetMainThread() + { + return mVM->GetMainThread(); + }; + + inline void Exit() + { + delete mVM; + mVM = nullptr; + } + + private: + + /// + /// ̱߳һluaһAsuraԶֻһִ붼 + /// УֻһΡ߳\ִջӦglobal_Stateģ + /// + /// struct lua_State *mainthread; + /// + /// ʹlua_newstate()ᴴһһglobal_Stateṹһ + /// ߳lua_Stateءglobal_State̹߳˵һ + /// ߳lua_newstate()⣬߳lua_newthread() + /// + Luax::LuaxVM* mVM; + + }; + + } +} + +namespace AEScripting = AsuraEngine::Scripting; + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/scripting/portable.hpp b/source/libs/asura-lib-utils/scripting/portable.hpp new file mode 100644 index 0000000..5badf8d --- /dev/null +++ b/source/libs/asura-lib-utils/scripting/portable.hpp @@ -0,0 +1,29 @@ +#ifndef __ASURA_ENGINE_PORTABLE_H__ +#define __ASURA_ENGINE_PORTABLE_H__ + +#include "../type.h" + +#include "lua_env.h" + +namespace AsuraEngine +{ + namespace Scripting + { + + /// + /// ҪעluanativeҪ̳дģ塣 + /// + template<typename T> + using Portable = Luax::LuaxNativeClass<T>; + + /// + /// ҪΪ࣬userdatamember ref̳д࣬ע̳С + /// + using NativeAccessor = Luax::ILuaxNativeAccessor; + + } +} + +namespace AEScripting = AsuraEngine::Scripting; + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/singleton.hpp b/source/libs/asura-lib-utils/singleton.hpp new file mode 100644 index 0000000..0d2777e --- /dev/null +++ b/source/libs/asura-lib-utils/singleton.hpp @@ -0,0 +1,59 @@ +#ifndef __ASURA_SINGLETON_H__ +#define __ASURA_SINGLETON_H__ + +#include "utils_config.h" + +namespace AsuraEngine +{ + + /// + /// ̳Singletonڵһʵʱʵ֮ٴʵᱨ + /// + template<class T> + class Singleton + { + public: + + static T* Get() + { + // ֮ǰûдһ + if (!instance) instance = new T; + // ʵ + return instance; + } + + static void Destroy() + { + delete instance; + instance = nullptr; + } + + protected: + + Singleton() + { + // instanceζִһʵǴġ + ASSERT(!instance); + // ʵΪʵ + instance = static_cast<T*>(this); + }; + + virtual ~Singleton() {}; + + static T* instance; + + private: + + Singleton(const Singleton& singleton); + + Singleton& operator = (const Singleton& singleton); + + }; + + // ʵʼΪ + template<class T> + T* Singleton<T>::instance = nullptr; + +} + +#endif // __ASURA_SINGLETON_H__
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/stringmap.cpp b/source/libs/asura-lib-utils/stringmap.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-utils/stringmap.cpp diff --git a/source/libs/asura-lib-utils/stringmap.hpp b/source/libs/asura-lib-utils/stringmap.hpp new file mode 100644 index 0000000..ddba128 --- /dev/null +++ b/source/libs/asura-lib-utils/stringmap.hpp @@ -0,0 +1,29 @@ +#ifndef __ASURA_ENGINE_STRINGMAP_H__ +#define __ASURA_ENGINE_STRINGMAP_H__ + +#include <string> + +namespace AsuraEngine +{ + + /// + /// һ˫һһӦӳ䣬shader uniformsstatemathine state parameterID + /// + template<typename key_type> + class StringMap + { + public: + + bool ContainsKey(const key_type& key); + + bool ContainsString(const String& str); + + std::string GetStringByKey(const key_type& key); + + key_type GetKeyByString(const String& str); + + }; + +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/binding/_coroutine.cpp b/source/libs/asura-lib-utils/threading/binding/_coroutine.cpp new file mode 100644 index 0000000..7f74cca --- /dev/null +++ b/source/libs/asura-lib-utils/threading/binding/_coroutine.cpp @@ -0,0 +1,40 @@ +#include "../coroutine.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace Threading + { + + LUAX_REGISTRY(Coroutine) + { + LUAX_REGISTER_METHODS(state, + { "New", _New }, + { "Run", _Run } + ); + } + + LUAX_POSTPROCESS(Coroutine) + { + + } + + // Coroutine.New() + LUAX_IMPL_METHOD(Coroutine, _New) + { + LUAX_STATE(L); + + return 0; + } + + // coroutine:Run() + LUAX_IMPL_METHOD(Coroutine, _Run) + { + LUAX_PREPARE(L, Coroutine); + + return 0; + } + + } +} diff --git a/source/libs/asura-lib-utils/threading/binding/_thread.cpp b/source/libs/asura-lib-utils/threading/binding/_thread.cpp new file mode 100644 index 0000000..a5aff03 --- /dev/null +++ b/source/libs/asura-lib-utils/threading/binding/_thread.cpp @@ -0,0 +1,210 @@ +#include "../thread.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace Threading + { + + LUAX_REGISTRY(Thread) + { + LUAX_REGISTER_METHODS(state, + { "New", _New }, + { "AddTask", _AddTask }, + { "Start", _Start }, + { "Idle", _Idle }, + { "Pause", _Pause }, + { "Resume", _Resume }, + { "Stop", _Stop }, + { "Join", _Join }, + { "IsRunning", _IsRunning }, + { "IsPaused", _IsPaused }, + { "IsStopped", _IsStopped }, + { "IsCurrent", _IsCurrent }, + { "Sleep", _Sleep }, + { "Post", _Post }, + { "GetName", _GetName }, + { "GetType", _GetType }, + { "GetState", _GetState } + ); + } + + LUAX_POSTPROCESS(Thread) + { + LUAX_REGISTER_ENUM(state, "EThreadType", + { "DEFERRED", THREAD_TYPE_DEFERRED }, + { "IMMEDIATE", THREAD_TYPE_IMMEDIATE } + ); + LUAX_REGISTER_ENUM(state, "EThreadState", + { "READY", THREAD_STATE_IDLE }, + { "RUNNING", THREAD_STATE_RUNNING }, + { "PAUSED", THREAD_STATE_PAUSED }, + { "STOPPED", THREAD_STATE_STOPPED } + ); + } + + // thread = Thread.New(thread_type, sleepTime, name) + LUAX_IMPL_METHOD(Thread, _New) + { + LUAX_STATE(L); + + ThreadType type = (ThreadType)state.GetValue<int>(1, THREAD_TYPE_DEFERRED); + uint sleepTime = state.GetValue<uint>(2,1); + cc8* name = state.GetValue<cc8*>(3, ""); + + Thread* thread = new Thread(state, type, sleepTime, name); + thread->PushLuaxUserdata(state); + + return 1; + } + + // thread:AddTask(task) + LUAX_IMPL_METHOD(Thread, _AddTask) + { + LUAX_PREPARE(L, Thread); + + Task* task = state.GetUserdata<Task>(2); + self->AddTask(task); + self->LuaxRetain<Task>(state, task); + return 0; + } + + // successed = thread:Start(isDeamon, stackSize) + LUAX_IMPL_METHOD(Thread, _Start) + { + LUAX_PREPARE(L, Thread); + + bool isDaemon = state.GetValue(2, true); + uint stackSize = state.GetValue(3, 0); + + state.Push(self->Start(isDaemon, stackSize)); + return 1; + } + + // thread:Idle() + LUAX_IMPL_METHOD(Thread, _Idle) + { + LUAX_PREPARE(L, Thread); + self->Idle(); + return 0; + } + + // thread:Pause() + LUAX_IMPL_METHOD(Thread, _Pause) + { + LUAX_PREPARE(L, Thread); + self->Pause(); + return 0; + } + + // thread:Resume() + LUAX_IMPL_METHOD(Thread, _Resume) + { + LUAX_PREPARE(L, Thread); + self->Resume(); + return 0; + } + + // thread:Stop() + LUAX_IMPL_METHOD(Thread, _Stop) + { + LUAX_PREPARE(L, Thread); + self->Stop(); + return 0; + } + + // thread:Join() + LUAX_IMPL_METHOD(Thread, _Join) + { + LUAX_PREPARE(L, Thread); + self->Join(); + return 0; + } + + // thread:IsRunning() + LUAX_IMPL_METHOD(Thread, _IsRunning) + { + LUAX_PREPARE(L, Thread); + state.Push(self->IsRunning()); + return 1; + } + + // thread:IsPaused() + LUAX_IMPL_METHOD(Thread, _IsPaused) + { + LUAX_PREPARE(L, Thread); + state.Push(self->IsPaused()); + return 1; + } + + // thread:IsStopped() + LUAX_IMPL_METHOD(Thread, _IsStopped) + { + LUAX_PREPARE(L, Thread); + state.Push(self->IsStopped()); + return 1; + } + + // thread:IsCurrent() + LUAX_IMPL_METHOD(Thread, _IsCurrent) + { + LUAX_PREPARE(L, Thread); + state.Push(self->IsCurrent()); + return 1; + } + + // Thread.Sleep(ms) + LUAX_IMPL_METHOD(Thread, _Sleep) + { + LUAX_STATE(L); + uint ms = state.GetValue(1, 0); +#ifdef _WIN32 + ::Sleep(ms); +#endif + return 0; + } + + // thread:Post() + LUAX_IMPL_METHOD(Thread, _Post) + { + LUAX_PREPARE(L, Thread); + self->Post(); + return 0; + } + + // thread:GetName() + LUAX_IMPL_METHOD(Thread, _GetName) + { + LUAX_PREPARE(L, Thread); + state.Push(self->GetName()); + return 1; + } + + // thread:GetType() + LUAX_IMPL_METHOD(Thread, _GetType) + { + LUAX_PREPARE(L, Thread); + state.Push(self->mType); + return 1; + } + + // thread:GetState() + LUAX_IMPL_METHOD(Thread, _GetState) + { + LUAX_PREPARE(L, Thread); + state.Push(self->mState); + return 1; + } + + // thread:SetSleepTime(sleepTime) + LUAX_IMPL_METHOD(Thread, _SetSleepTime) + { + LUAX_PREPARE(L, Thread); + uint time = state.CheckValue<uint>(2); + self->SetSleepTime(time); + return 0; + } + + } +} diff --git a/source/libs/asura-lib-utils/threading/coroutine.cpp b/source/libs/asura-lib-utils/threading/coroutine.cpp new file mode 100644 index 0000000..9f65c5f --- /dev/null +++ b/source/libs/asura-lib-utils/threading/coroutine.cpp @@ -0,0 +1,16 @@ +#include "coroutine.h" + +namespace AsuraEngine +{ + namespace Threading + { +/* + Coroutine::Coroutine() + { + + } +*/ + + + } +} diff --git a/source/libs/asura-lib-utils/threading/coroutine.h b/source/libs/asura-lib-utils/threading/coroutine.h new file mode 100644 index 0000000..01af654 --- /dev/null +++ b/source/libs/asura-lib-utils/threading/coroutine.h @@ -0,0 +1,40 @@ +#ifndef __ASURA_COROUTINE_H__ +#define __ASURA_COROUTINE_H__ + +#include "../scripting/portable.hpp" + +namespace AsuraEngine +{ + namespace Threading + { + + /// + /// luaЭ̣һЩ + /// + class Coroutine ASURA_FINAL + : public AEScripting::Portable<Coroutine> + { + public: + + LUAX_DECL_FACTORY(Coroutine); + + + + private: + + /// + /// ǰЭ̵state + /// + lua_State* mThreadState; + + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_Run); + + }; + + } +} + +namespace AEThreading = AsuraEngine::Threading; + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/mutex.cpp b/source/libs/asura-lib-utils/threading/mutex.cpp new file mode 100644 index 0000000..663ac28 --- /dev/null +++ b/source/libs/asura-lib-utils/threading/mutex.cpp @@ -0,0 +1,106 @@ +#include <asura-lib-utils/exceptions/exception.h> + +#include "mutex.h" + +namespace AsuraEngine +{ + namespace Threading + { + +#define try_create_mutex(impl)\ + if (!mImpl) \ + { \ + try \ + { \ + mImpl = new impl(); \ + } \ + catch (Exception& e) \ + { \ + mImpl = nullptr; \ + } \ + } + + Mutex::Mutex() + : mImpl(nullptr) + { +#if ASURA_MUTEX_WIN32_CRITICLE_SECTION + try_create_mutex(MutexImplWin32_CS); +#endif +#if ASURA_MUTEX_WIN32_KERNAL_MUTEX + try_create_mutex(MutexImplWin32_KM); +#endif + ASSERT(mImpl); + } + + Mutex::~Mutex() + { + delete mImpl; + } + + void Mutex::Lock() + { + ASSERT(mImpl); + + mImpl->Lock(); + } + + void Mutex::Unlock() + { + ASSERT(mImpl); + + mImpl->Unlock(); + } + +#if ASURA_MUTEX_WIN32_CRITICLE_SECTION + + MutexImplWin32_CS::MutexImplWin32_CS() + { + ::InitializeCriticalSection(&mMutex); + } + + MutexImplWin32_CS::~MutexImplWin32_CS() + { + ::DeleteCriticalSection(&mMutex); + } + + void MutexImplWin32_CS::Lock() + { + ::EnterCriticalSection(&mMutex); + } + + void MutexImplWin32_CS::Unlock() + { + ::LeaveCriticalSection(&mMutex); + } + +#endif // ASURA_MUTEX_WIN32_CRITICLE_SECTION + +#if ASURA_MUTEX_WIN32_KERNAL_MUTEX + + MutexImplWin32_KM::MutexImplWin32_KM() + { + mHandle = ::CreateMutex(NULL, FALSE, NULL); + if (!mHandle) + throw Exception("Cant use win32 mutex."); + } + + MutexImplWin32_KM::~MutexImplWin32_KM() + { + ::CloseHandle(mHandle); + mHandle = NULL; + } + + void MutexImplWin32_KM::Lock() + { + ::WaitForSingleObject(mHandle, INFINITE); + } + + void MutexImplWin32_KM::Unlock() + { + ::ReleaseMutex(mHandle); + } + +#endif // ASURA_MUTEX_WIN32_KERNAL_MUTEX + + } +} diff --git a/source/libs/asura-lib-utils/threading/mutex.h b/source/libs/asura-lib-utils/threading/mutex.h new file mode 100644 index 0000000..7e7d877 --- /dev/null +++ b/source/libs/asura-lib-utils/threading/mutex.h @@ -0,0 +1,126 @@ +#ifndef __ASURA_MUTEX_H__ +#define __ASURA_MUTEX_H__ + +#include <asura-lib-utils/type.h> + +#include "../utils_config.h" + +#if ASURA_THREAD_WIN32 + #include <windows.h> +#endif + +namespace AsuraEngine +{ + namespace Threading + { + + class MutexImpl; + + class Mutex + { + public: + + Mutex(); + ~Mutex(); + + void Lock(); + void Unlock(); + + private: + + MutexImpl* mImpl; + + }; + + class _mutex_locker + { + public: + _mutex_locker(Mutex& mutex) + : m(mutex) + { + m.Lock(); + }; + ~_mutex_locker() + { + m.Unlock(); + } + private: + void* operator new(size_t); + Mutex& m; + }; + +// ڵջӴλÿʼջΪٽ +#define lock(mutex) _mutex_locker _asura_scoped_lock_0x0(mutex) +#define lock2(mutex) _mutex_locker _asura_scoped_lock_0x1(mutex) +#define lock3(mutex) _mutex_locker _asura_scoped_lock_0x2(mutex) +#define lock4(mutex) _mutex_locker _asura_scoped_lock_0x3(mutex) +#define lock5(mutex) _mutex_locker _asura_scoped_lock_0x4(mutex) + + ASURA_ABSTRACT class MutexImpl + { + public: + + MutexImpl() {}; + virtual ~MutexImpl() {}; + + virtual void Lock() = 0; + virtual void Unlock() = 0; + + }; + +#if ASURA_MUTEX_WIN32_CRITICLE_SECTION + + //https://blog.csdn.net/l799623787/article/details/18259949 + class MutexImplWin32_CS ASURA_FINAL : public MutexImpl + { + public: + + MutexImplWin32_CS(); + ~MutexImplWin32_CS(); + + void Lock() override; + void Unlock() override; + + private: + + //HANDLE mHandle; + CRITICAL_SECTION mMutex; + + }; + +#endif // ASURA_MUTEX_WIN32_CRITICLE_SECTION + +#if ASURA_MUTEX_WIN32_KERNAL_MUTEX + + class MutexImplWin32_KM ASURA_FINAL : public MutexImpl + { + public: + + MutexImplWin32_KM(); + ~MutexImplWin32_KM(); + + void Lock() override; + void Unlock() override; + + private: + + HANDLE mHandle; + + }; + +#endif // ASURA_MUTEX_WIN32_KERNAL_MUTEX + +#if ASURA_THREAD_STD + + class MutexImplSTD ASURA_FINAL : public MutexImpl + { + }; + +#endif // ASURA_THREAD_STD + + } +} + +namespace AEThreading = AsuraEngine::Threading; + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/semaphore.cpp b/source/libs/asura-lib-utils/threading/semaphore.cpp new file mode 100644 index 0000000..d59ec78 --- /dev/null +++ b/source/libs/asura-lib-utils/threading/semaphore.cpp @@ -0,0 +1,88 @@ +#include "../exceptions/exception.h" +#include "../type.h" + +#include "semaphore.h" + +namespace AsuraEngine +{ + namespace Threading + { + +#define try_create_semaphore(impl) \ + if (!mImpl) \ + { \ + try \ + { \ + mImpl = new impl(init_count); \ + } \ + catch (Exception& e) \ + { \ + mImpl = nullptr; \ + } \ + } + + Semaphore::Semaphore(unsigned int init_count) + : mImpl(nullptr) + { +#ifdef ASURA_THREAD_WIN32 + try_create_semaphore(SemaphoreWin32); +#endif + ASSERT(mImpl); + } + + Semaphore::~Semaphore() + { + if (mImpl) delete mImpl; + } + + void Semaphore::Signal() + { + ASSERT(mImpl); + mImpl->Signal(); + } + + void Semaphore::Wait(int timeout) + { + ASSERT(mImpl); + mImpl->Wait(timeout); + } + +#if ASURA_THREAD_WIN32 + + SemaphoreWin32::SemaphoreWin32(unsigned int init_value) + : SemaphoreImpl(init_value) + { + mSem = CreateSemaphore(NULL, init_value, UINT_MAX, NULL); + if (!mSem) + throw Exception("Cant use win32 semaphore."); + } + + SemaphoreWin32::~SemaphoreWin32() + { + CloseHandle(mSem); + } + + void SemaphoreWin32::Signal() + { + InterlockedIncrement(&mCount); + if (ReleaseSemaphore(mSem, 1, NULL) == FALSE) + InterlockedDecrement(&mCount); + } + + bool SemaphoreWin32::Wait(int timeout) + { + int result; + result = WaitForSingleObject(mSem, timeout < 0 ? INFINITE : timeout); + if (result == WAIT_OBJECT_0) + { + InterlockedDecrement(&mCount); + return true; + } + else + return false; + } + +#endif // ASURA_THREAD_WIN32 + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/semaphore.h b/source/libs/asura-lib-utils/threading/semaphore.h new file mode 100644 index 0000000..80773d8 --- /dev/null +++ b/source/libs/asura-lib-utils/threading/semaphore.h @@ -0,0 +1,70 @@ +#ifndef __ASURA_SEMAPHORE_H__ +#define __ASURA_SEMAPHORE_H__ + +#include "../utils_config.h" + +#if ASURA_THREAD_WIN32 +#include <windows.h> +#endif + +namespace AsuraEngine +{ + namespace Threading + { + + class SemaphoreImpl; + + /// + /// ź + /// + class Semaphore + { + public: + + Semaphore(unsigned int init_count = 1); + ~Semaphore(); + + void Signal(); + void Wait(int timeout = 0); + + private: + SemaphoreImpl* mImpl; + }; + + class SemaphoreImpl + { + public: + SemaphoreImpl(unsigned int init_value) + : mCount(init_value) + { + }; + virtual ~SemaphoreImpl() {}; + virtual void Signal() = 0; + virtual bool Wait(int timeout) = 0; + inline int Current() { return mCount; } + protected: + unsigned int mCount; + }; + +#define wait(sem) sem.Wait(); +#define signal(sem) sem.Signal(); + +#if ASURA_THREAD_WIN32 + + class SemaphoreWin32 : public SemaphoreImpl + { + public: + SemaphoreWin32(unsigned int init_value); + ~SemaphoreWin32(); + void Signal() override; + bool Wait(int timeout) override; + private: + HANDLE mSem; + }; + +#endif // ASURA_THREAD_WIN32 + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/task.cpp b/source/libs/asura-lib-utils/threading/task.cpp new file mode 100644 index 0000000..2e84ed4 --- /dev/null +++ b/source/libs/asura-lib-utils/threading/task.cpp @@ -0,0 +1,12 @@ +#include "task.h" +#include "../scripting/lua_env.h" + +using namespace AEScripting; + +namespace AsuraEngine +{ + namespace Threading + { + + } +} diff --git a/source/libs/asura-lib-utils/threading/task.h b/source/libs/asura-lib-utils/threading/task.h new file mode 100644 index 0000000..fb7aa5f --- /dev/null +++ b/source/libs/asura-lib-utils/threading/task.h @@ -0,0 +1,45 @@ +#ifndef __ASURA_THRAD_TASK_H__ +#define __ASURA_THRAD_TASK_H__ + +#include <asura-lib-utils/type.h> +#include <asura-lib-utils/scripting/portable.hpp> + +namespace AsuraEngine +{ + namespace Threading + { + + /// + /// ϣһ̴̳߳TaskдExecute + /// + ASURA_ABSTRACT class Task + : public virtual AEScripting::NativeAccessor + { + public: + + Task() {}; + virtual ~Task() {}; + + /// + /// ִɺtrueûص + /// + virtual bool Execute() = 0; + + /// + /// ûصinvoke threadص + /// + virtual void Invoke(lua_State* invokeThreaad) = 0; + + protected: + + // ȡص + Luax::LuaxMemberRef mCallback; + + }; + + } +} + +namespace AEThreading = AsuraEngine::Threading; + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/thread.cpp b/source/libs/asura-lib-utils/threading/thread.cpp new file mode 100644 index 0000000..0f4f5da --- /dev/null +++ b/source/libs/asura-lib-utils/threading/thread.cpp @@ -0,0 +1,272 @@ +#include "thread.h" + +#include "thread_impl_win32.h" +#include "thread_impl_posix.h" +#include "thread_impl_sdl.h" +#include "thread_impl_std.h" + +namespace AsuraEngine +{ + namespace Threading + { + + Thread::Thread(lua_State* luaThread, ThreadType type /*= THREAD_TYPE_DEFERRED*/, uint sleepTime /*= 0*/, const std::string& name /*= ""*/) + : mName(name) + , mState(THREAD_STATE_IDLE) + , mType(type) + , mLuaThread(luaThread) + , mCallbackThread(nullptr) + , mSleepTime(sleepTime) + { + LUAX_STATE(luaThread); + if (type == THREAD_TYPE_IMMEDIATE) + { + Luax::LuaxVM* vm = state.GetVM(); + ASSERT(vm); + mCallbackThread = vm->CreateThread(); + ASSERT(mCallbackThread); + SetLuaxMemberRef(state, mCallbackThreadRef, -1); + state.Pop(); // callback thread + } + } + + Thread::~Thread() + { + if (mImpl) + { + delete mImpl; + mImpl = nullptr; + } + } + + bool Thread::AddTask(Task* task) + { + lock(mTaskQueueMutex); + mTaskQueue.push(task); + return true; + } + + uint Thread::GetTaskCount() + { + return mTaskQueue.size(); + } + + void Thread::Idle() + { + mState = THREAD_STATE_IDLE; + } + +#define try_start_thread(impl)\ + if (!mImpl) \ + { \ + mImpl = new impl(); \ + if (!mImpl->Start(this, stacksize)) \ + { \ + delete mImpl; \ + mImpl = nullptr; \ + } \ + } + + bool Thread::Start(bool isDaemon /*= true*/, uint32 stacksize /*= 0*/) + { + if (mState != THREAD_STATE_IDLE) + return false; + + // Ѿһ֮ǰģر + if (mImpl) + { + delete mImpl; + mImpl = nullptr; + } + +#if ASURA_THREAD_WIN32 + try_start_thread(ThreadImplWin32); +#endif + + if (!mImpl) + return false; + + mIsDaemon = isDaemon; + mStateMutex.Lock(); + mState = THREAD_STATE_RUNNING; + mStateMutex.Unlock(); + } + + void Thread::Pause() + { + ASSERT(mImpl); + + lock(mStateMutex); + mState = THREAD_STATE_PAUSED; + } + + void Thread::Resume() + { + ASSERT(mImpl); + + lock(mStateMutex); + if(mState == THREAD_STATE_PAUSED) + mState = THREAD_STATE_RUNNING; + } + + void Thread::Stop() + { + ASSERT(mImpl); + + lock(mStateMutex); + mState = THREAD_STATE_STOPPED; + } + + void Thread::PauseSync() + { + Pause(); + wait(mSemPause); + } + + void Thread::ResumeSync() + { + Resume(); + wait(mSemResume); + } + + void Thread::StopSync() + { + Stop(); + wait(mSemStop); + } + + void Thread::Join() + { + ASSERT(mImpl); + mImpl->Join(); + } + + ThreadState Thread::GetState() + { + ThreadState state; + mStateMutex.Lock(); + state = mState; + mStateMutex.Unlock(); + return state; + } + + bool Thread::IsRunning() + { + ASSERT(mImpl); + + return GetState() == THREAD_STATE_RUNNING; + } + + bool Thread::IsPaused() + { + ASSERT(mImpl); + + return GetState() == THREAD_STATE_PAUSED; + } + + bool Thread::IsStopped() + { + ASSERT(mImpl); + + return GetState() == THREAD_STATE_STOPPED; + } + + bool Thread::IsCurrent() + { + ASSERT(mImpl); + + return mImpl->IsCurrent(); + } + + const std::string& Thread::GetName() + { + return mName; + } + + void Thread::Process() + { + LUAX_STATE(mLuaThread); + + do{ + if (IsRunning()) + { + while (!mTaskQueue.empty()) + { + Task* task = mTaskQueue.front(); + if (task && task->Execute()) + { + if (mType == THREAD_TYPE_DEFERRED) + { + mFinishedMutex.Lock(); + mFinishedTasks.push(task); + mFinishedMutex.Unlock(); + } + else if (mType == THREAD_TYPE_IMMEDIATE) + { + task->Invoke(mCallbackThread); + this->LuaxRelease<Task>(state, task); + } + mTaskQueueMutex.Lock(); + mTaskQueue.pop(); + mTaskQueueMutex.Unlock(); + } + } + } + + // ˳ѭ + if (IsStopped()) + break; + + // CPUʹ + Sleep(mSleepTime); + + } while (mIsDaemon); + + // ػ̣߳еstop״̬ + if (!mIsDaemon) + Stop(); + + signal(mSemStop); + + // ״̬ΪIdle + Idle(); + } + + /// + /// ӳģʽص + /// + void Thread::Post() + { + ASSERT(mType == THREAD_TYPE_DEFERRED); + + LUAX_STATE(mLuaThread); + while (!mFinishedTasks.empty()) + { + Task* task = mFinishedTasks.front(); + if (task) + { + task->Invoke(mLuaThread); + this->LuaxRelease<Task>(state, task); + mFinishedMutex.Lock(); + mFinishedTasks.pop(); + mFinishedMutex.Unlock(); + } + } + } + + void Thread::Sleep(uint ms) + { + ASSERT(mImpl); + if (mImpl) + { + mImpl->Sleep(ms); + } + } + + void Thread::SetSleepTime(uint ms) + { + mSleepTime = ms; + } + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/thread.h b/source/libs/asura-lib-utils/threading/thread.h new file mode 100644 index 0000000..0e75770 --- /dev/null +++ b/source/libs/asura-lib-utils/threading/thread.h @@ -0,0 +1,221 @@ +#ifndef __ASURA_THREAD_H__ +#define __ASURA_THREAD_H__ + +#include <string> +#include <queue> + +#include <asura-lib-utils/scripting/portable.hpp> + +#include "task.h" +#include "mutex.h" +#include "semaphore.h" + +namespace AsuraEngine +{ + namespace Threading + { + + class ThreadImpl; + + /// + /// ̵߳ļֲͬʵ֣ + /// 1: Deferredӳģʽ߳ϵɺҪ̵ֶ߳Post + /// ̵߳ص첽Ϊͬlua_Stateͻ⡣ + /// 2: Immediateģʽÿһ߳άһlua_newthreadlua_State + /// صڲͬlua_Stateеãⲻ̷ͬ߳ͬһlua_State + /// + enum ThreadType + { + THREAD_TYPE_DEFERRED, + THREAD_TYPE_IMMEDIATE, + }; + + enum ThreadState + { + THREAD_STATE_IDLE, ///< ãδں˶ + THREAD_STATE_RUNNING, ///< ѭ + THREAD_STATE_PAUSED, ///< ѭͣ + THREAD_STATE_STOPPED, ///< ˳ѭ + }; + + /// + /// ߳壬ÿ߳άһtask queue + /// + class Thread ASURA_FINAL + : public AEScripting::Portable<Thread> + { + public: + + LUAX_DECL_FACTORY(Thread); + + Thread(lua_State* luaThread, ThreadType type = THREAD_TYPE_DEFERRED, uint sleepTime = 1, const std::string& name = ""); + ~Thread(); + + bool AddTask(Task* task); + /// + /// õȴ + /// + uint GetTaskCount(); + + void Idle(); + + /// + /// ں˶Сdaemonȴֶstopijʱ̶ɺԶstop + /// + bool Start(bool daemon = true, uint32 stacksize = 0); + + /// + /// ͬ߳̿ƣʵʱġҪ߳ʹIsȷϵָ״̬ + /// + void Pause(); + void Resume(); + void Stop(); + + /// + /// ͬ߳̿ƣȷźźִС̵߳ȴ + /// + void PauseSync(); + void ResumeSync(); + void StopSync(); + + /// + /// ̵߳ȴ߳̽żִС + /// + void Join(); + + ThreadState GetState(); + + /// + /// ߳״̬ + /// 1: IdleУ̴߳Ĭ״̬ʱStart + /// 2: RunningУں˶´Ѿں˵УTask + /// 3: PausedͣȻںУ˶Ĵͣ + /// 4: StoppedֹͣȻںУѾ + /// + bool IsIdle(); + bool IsRunning(); + bool IsPaused(); + bool IsStopped(); + + bool IsCurrent(); + + /// + /// ִС + /// + void Process(); + + const std::string& GetName(); + + /// + /// ص + /// + void Post(); + + /// + /// ߺ + /// + void Sleep(uint ms); + + /// + /// ʱ + /// + void SetSleepTime(uint ms); + + private: + + //----------------------------------------------------------------------------// + + LUAX_DECL_ENUM(ThreadType); + LUAX_DECL_ENUM(ThreadState); + + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_AddTask); + LUAX_DECL_METHOD(_Start); + LUAX_DECL_METHOD(_Idle); + LUAX_DECL_METHOD(_Pause); + LUAX_DECL_METHOD(_Resume); + LUAX_DECL_METHOD(_Stop); + LUAX_DECL_METHOD(_Join); + LUAX_DECL_METHOD(_IsRunning); + LUAX_DECL_METHOD(_IsPaused); + LUAX_DECL_METHOD(_IsStopped); + LUAX_DECL_METHOD(_IsCurrent); + LUAX_DECL_METHOD(_Sleep); + LUAX_DECL_METHOD(_Post); + LUAX_DECL_METHOD(_GetName); + LUAX_DECL_METHOD(_GetType); + LUAX_DECL_METHOD(_GetState); + LUAX_DECL_METHOD(_SetSleepTime); + + //----------------------------------------------------------------------------// + + /// + /// ˴Ƿػģʽ + /// + bool mIsDaemon; + + lua_State* mLuaThread; + + ThreadImpl* mImpl; + std::string mName; + ThreadType mType; + uint mSleepTime; + + ThreadState mState; + Mutex mStateMutex; + + /// + /// ͬصź + /// + Semaphore mSemPause; + Semaphore mSemResume; + Semaphore mSemStop; + + /// + /// С + /// + std::queue<Task*> mTaskQueue; + Mutex mTaskQueueMutex; + + /// + /// ӳģʽʹ + /// + std::queue<Task*> mFinishedTasks; + Mutex mFinishedMutex; + + /// + /// ģʽʹãصʹõlua߳ + /// + lua_State* mCallbackThread; + Luax::LuaxMemberRef mCallbackThreadRef; + + }; + + /// + /// ̵߳ľʵ֣ûģһֲԣ + /// 1: win32 + /// 2: posix + /// 3: SDL + /// 4: std::thread + /// + ASURA_ABSTRACT class ThreadImpl + { + public: + ThreadImpl() {}; + virtual ~ThreadImpl() {}; + + virtual bool Start(Thread* thread, uint32 stacksize = 0) = 0; + virtual void Join() = 0; + virtual void Kill() = 0; + + virtual void Sleep(uint ms) = 0; + + virtual bool IsRunning() = 0; + virtual bool IsCurrent() = 0; + + }; + + } +} + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/thread_impl_posix.cpp b/source/libs/asura-lib-utils/threading/thread_impl_posix.cpp new file mode 100644 index 0000000..d2ad7af --- /dev/null +++ b/source/libs/asura-lib-utils/threading/thread_impl_posix.cpp @@ -0,0 +1,9 @@ +#include "thread_impl_posix.h" + +namespace AsuraEngine +{ + namespace Threading + { + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/thread_impl_posix.h b/source/libs/asura-lib-utils/threading/thread_impl_posix.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-utils/threading/thread_impl_posix.h diff --git a/source/libs/asura-lib-utils/threading/thread_impl_sdl.cpp b/source/libs/asura-lib-utils/threading/thread_impl_sdl.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-utils/threading/thread_impl_sdl.cpp diff --git a/source/libs/asura-lib-utils/threading/thread_impl_sdl.h b/source/libs/asura-lib-utils/threading/thread_impl_sdl.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-utils/threading/thread_impl_sdl.h diff --git a/source/libs/asura-lib-utils/threading/thread_impl_std.cpp b/source/libs/asura-lib-utils/threading/thread_impl_std.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-utils/threading/thread_impl_std.cpp diff --git a/source/libs/asura-lib-utils/threading/thread_impl_std.h b/source/libs/asura-lib-utils/threading/thread_impl_std.h new file mode 100644 index 0000000..0e7d3da --- /dev/null +++ b/source/libs/asura-lib-utils/threading/thread_impl_std.h @@ -0,0 +1,43 @@ +#ifndef __ASURA_THREAD_STD_H__ +#define __ASURA_THREAD_STD_H__ + +#include "../utils_config.h" + +#if ASURA_THREAD_STD + +#include <windows.h> + +#include "thread.h" + +namespace AsuraEngine +{ + namespace Threading + { + + /// + /// Threadstd::threadʵ֡ + /// + class ThreadImplSTD : public ThreadImpl + { + public: + + ThreadImplSTD(); + ~ThreadImplSTD(); + + bool Start(Thread* thread, uint32 stacksize) override; + void Join() override; + void Kill() override; + + bool IsRunning() override; + bool IsCurrent() override; + + private: + + }; + + } +} + +#endif // #if ASURA_THREAD_STD + +#endif // __ASURA_THREAD_STD_H__
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/thread_impl_win32.cpp b/source/libs/asura-lib-utils/threading/thread_impl_win32.cpp new file mode 100644 index 0000000..6871c2d --- /dev/null +++ b/source/libs/asura-lib-utils/threading/thread_impl_win32.cpp @@ -0,0 +1,76 @@ +#include "thread_impl_win32.h" +#include "thread.h" + +#include <iostream> + +namespace AsuraEngine +{ + namespace Threading + { + + static DWORD WINAPI _thread_win32_runner(LPVOID param) + { + Thread* thread = (Thread*)param; + thread->Process(); + return 0; + } + + ThreadImplWin32::ThreadImplWin32() + { + } + + ThreadImplWin32::~ThreadImplWin32() + { + if (!mHandle) return; + ::CloseHandle(mHandle); + mHandle = 0; + } + + bool ThreadImplWin32::Start(Thread* thread, uint32 stacksize/*=0*/) + { + assert(!IsRunning()); + mHandle = ::CreateThread( + NULL + , stacksize + , _thread_win32_runner + , thread + , 0 /*е*/ + , NULL); + + return mHandle; + } + + void ThreadImplWin32::Join() + { + // ̵߳ȴ̷߳ + ::WaitForSingleObject(mHandle, INFINITE); + } + + void ThreadImplWin32::Kill() + { + ::TerminateThread(mHandle, FALSE); + } + + void ThreadImplWin32::Sleep(uint ms) + { + ::Sleep(ms); + } + + bool ThreadImplWin32::IsRunning() + { + if (mHandle) { + DWORD exitCode = 0; + // https://blog.csdn.net/yuanmeng567/article/details/19485719 + ::GetExitCodeThread(mHandle, &exitCode); + return exitCode == STILL_ACTIVE; + } + return false; + } + + bool ThreadImplWin32::IsCurrent() + { + return mHandle == ::GetCurrentThread(); + } + + } +}
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/thread_impl_win32.h b/source/libs/asura-lib-utils/threading/thread_impl_win32.h new file mode 100644 index 0000000..a22aeef --- /dev/null +++ b/source/libs/asura-lib-utils/threading/thread_impl_win32.h @@ -0,0 +1,47 @@ +#ifndef __ASURA_THREAD_WIN32_H__ +#define __ASURA_THREAD_WIN32_H__ + +#include "../utils_config.h" + +#if ASURA_THREAD_WIN32 + +#include <windows.h> + +#include "thread.h" + +namespace AsuraEngine +{ + namespace Threading + { + + /// + /// Threadwin32ʵ֡ + /// + class ThreadImplWin32 : public ThreadImpl + { + public: + + ThreadImplWin32(); + ~ThreadImplWin32(); + + bool Start(Thread* thread, uint32 stacksize) override; + void Join() override; + void Kill() override; + + void Sleep(uint ms) override; + + bool IsRunning() override; + bool IsCurrent() override; + + private: + + HANDLE mHandle; + + }; + + } +} + +#endif // #if ASURA_THREAD_WIN32 + +#endif // __ASURA_THREAD_WIN32_H__
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/threading/thread_task.cpp b/source/libs/asura-lib-utils/threading/thread_task.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/libs/asura-lib-utils/threading/thread_task.cpp diff --git a/source/modules/asura-utils/threading/thread_task.h b/source/libs/asura-lib-utils/threading/thread_task.h index 6592191..1ea0a1a 100644 --- a/source/modules/asura-utils/threading/thread_task.h +++ b/source/libs/asura-lib-utils/threading/thread_task.h @@ -1,8 +1,8 @@ #ifndef __ASURA_THRAD_TASK_H__ #define __ASURA_THRAD_TASK_H__ -#include <asura-utils/type.h> -#include <asura-utils/scripting/portable.hpp> +#include <asura-lib-utils/type.h> +#include <asura-lib-utils/scripting/portable.hpp> namespace AsuraEngine { diff --git a/source/libs/asura-lib-utils/type.h b/source/libs/asura-lib-utils/type.h new file mode 100644 index 0000000..1ed2d42 --- /dev/null +++ b/source/libs/asura-lib-utils/type.h @@ -0,0 +1,85 @@ +#ifndef __ASURA_UTILS_TYPE_H__ +#define __ASURA_UTILS_TYPE_H__ + +#include <cstdlib> +#include <stdint.h> + +namespace AsuraEngine +{ + + //--------------------------------------------------------------------------------// + + typedef int8_t int8; + typedef uint8_t uint8; + //typedef uint8 byte; + typedef char byte; + typedef int16_t int16; + typedef uint16_t uint16; + typedef int32_t int32; + typedef uint32_t uint32; + typedef int64_t int64; + typedef uint64_t uint64; + + typedef uint32_t uint; + typedef int32_t sint; + + typedef std::size_t size_t; + + typedef const char cc8; + + //--------------------------------------------------------------------------------// + +#ifndef ASSERT + #ifdef NDEBUG + #define ASSERT(x) { false ? (void)(x) : (void)0; } + #else + #ifdef _WIN32 + #define ASURA_DEBUG_BREAK() __debugbreak() + #else + #define ASURA_DEBUG_BREAK() raise(SIGTRAP) + #endif + #define ASSERT(x) do { const volatile bool asura_assert_b____ = !(x); if(asura_assert_b____) ASURA_DEBUG_BREAK(); } while (false) + #endif +#endif + + //--------------------------------------------------------------------------------// + +#ifdef _WIN32 + #define ASURA_FINAL final + #define ASURA_LIBRARY_EXPORT __declspec(dllexport) + #define ASURA_LIBRARY_IMPORT __declspec(dllimport) + #define ASURA_FORCE_INLINE __forceinline + #define ASURA_RESTRICT __restrict + #define ASURA_ATTRIBUTE_USED + #define ASURA_ABSTRACT + #define ASURA_API ASURA_LIBRARY_EXPORT + + #define ASURA_WINDOWS 1 +#else + #define ASURA_FINAL final + #define ASURA_LIBRARY_EXPORT __attribute__((visibility("default"))) + #define ASURA_LIBRARY_IMPORT + #define ASURA_FORCE_INLINE __attribute__((always_inline)) inline + #define ASURA_RESTRICT __restrict__ + #define ASURA_ATTRIBUTE_USED __attribute__((used)) + #define ASURA_ABSTRACT + #define ASURA_API ASURA_LIBRARY_EXPORT +#endif + + /// + /// ò + /// +#define ASURA_OUT +#define ASURA_REF + /// + /// ƶָȨ + /// +#define ASURA_MOVE + + //--------------------------------------------------------------------------------// + +#define ASURA_SDL_HOST 1 + +} // namespace AsuraEngine + +#endif // __ASURA_CONFIG_H__
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/utils.h b/source/libs/asura-lib-utils/utils.h new file mode 100644 index 0000000..ce1c6a1 --- /dev/null +++ b/source/libs/asura-lib-utils/utils.h @@ -0,0 +1,6 @@ +#ifndef __ASURA_UTILS_H__ +#define __ASURA_UTILS_H__ + +#include "utils_module.h" + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/utils_config.h b/source/libs/asura-lib-utils/utils_config.h new file mode 100644 index 0000000..02837dc --- /dev/null +++ b/source/libs/asura-lib-utils/utils_config.h @@ -0,0 +1,10 @@ +#ifndef __ASURA_UTILS_CONFIG_H__ +#define __ASURA_UTILS_CONFIG_H__ + +#define ASURA_THREAD_WIN32 1 +#define ASURA_THREAD_STD 1 + +#define ASURA_MUTEX_WIN32_CRITICLE_SECTION 1 +#define ASURA_MUTEX_WIN32_KERNAL_MUTEX 1 + +#endif
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/utils_module.cpp b/source/libs/asura-lib-utils/utils_module.cpp new file mode 100644 index 0000000..61780e6 --- /dev/null +++ b/source/libs/asura-lib-utils/utils_module.cpp @@ -0,0 +1,25 @@ +#include "utils_module.h" + +using namespace AsuraEngine::IO; +using namespace AsuraEngine::Threading; + +namespace AsuraEngine +{ + + void UtilsModule::Initialize(Luax::LuaxState& state) + { + // IO + LUAX_REGISTER_SINGLETON(state, Filesystem); + LUAX_REGISTER_FACTORY(state, DataBuffer); + LUAX_REGISTER_FACTORY(state, FileData); + LUAX_REGISTER_FACTORY(state, File); + LUAX_REGISTER_FACTORY(state, IOTask); + // Threading + LUAX_REGISTER_FACTORY(state, Thread); + } + + void UtilsModule::Finalize(Luax::LuaxState& state) + { + } + +}
\ No newline at end of file diff --git a/source/libs/asura-lib-utils/utils_module.h b/source/libs/asura-lib-utils/utils_module.h new file mode 100644 index 0000000..e802730 --- /dev/null +++ b/source/libs/asura-lib-utils/utils_module.h @@ -0,0 +1,32 @@ +#ifndef __ASURA_LIBS_UTIL_MODULE_H__ +#define __ASURA_LIBS_UTIL_MODULE_H__ + +#include "io/file_system.h" +#include "io/data_buffer.h" +#include "io/file_data.h" +#include "io/file.h" +#include "io/io_task.h" + +#include "threading/thread.h" + +#include "module.h" + +namespace AsuraEngine +{ + + /// + /// Asuraģ + /// + class UtilsModule ASURA_FINAL : public Module + { + public: + + void Initialize(Luax::LuaxState& state) override; + + void Finalize(Luax::LuaxState& state) override; + + }; + +} + +#endif
\ No newline at end of file diff --git a/source/modules/asura-box2d/physics/body.h b/source/modules/asura-box2d/physics/body.h index 57295c6..deddaaf 100644 --- a/source/modules/asura-box2d/physics/body.h +++ b/source/modules/asura-box2d/physics/body.h @@ -11,6 +11,7 @@ namespace AsuraEngine { class World; + class Joint; enum BodyType { @@ -28,10 +29,10 @@ namespace AsuraEngine LUAX_DECL_FACTORY(Body); - b2Body *body; - private: + friend class Joint; + //----------------------------------------------------------------------------// LUAX_DECL_ENUM(BodyType); @@ -55,6 +56,8 @@ namespace AsuraEngine //----------------------------------------------------------------------------// + b2Body *body; + World* mWorld; }; diff --git a/source/modules/asura-core/application.cpp b/source/modules/asura-core/application.cpp index 1ef9414..a630d4c 100644 --- a/source/modules/asura-core/application.cpp +++ b/source/modules/asura-core/application.cpp @@ -17,7 +17,7 @@ namespace AsuraEngine bool Application::InitSubModules(uint flag) { - + return false; } }
\ No newline at end of file diff --git a/source/modules/asura-core/core_module.cpp b/source/modules/asura-core/core_module.cpp index e6b0dac..989ec3e 100644 --- a/source/modules/asura-core/core_module.cpp +++ b/source/modules/asura-core/core_module.cpp @@ -2,7 +2,6 @@ using namespace AEThreading; using namespace AEGraphics; -using namespace AEWnd; namespace AsuraEngine { @@ -13,7 +12,7 @@ namespace AsuraEngine LUAX_REGISTER_ABSTRACT_FACTORY(state, Texture); LUAX_REGISTER_FACTORY(state, Image); // Wnd - LUAX_REGISTER_SINGLETON(state, Window); + LUAX_REGISTER_SINGLETON(state, AEWindow::Window); // Threading //LUAX_REGISTER_FACTORY(state, ThreadEx); } diff --git a/source/modules/asura-core/core_module.h b/source/modules/asura-core/core_module.h index 613a806..443aea4 100644 --- a/source/modules/asura-core/core_module.h +++ b/source/modules/asura-core/core_module.h @@ -6,7 +6,7 @@ #include "graphics/image.h" #include "graphics/texture.h" -#include "wnd/window.h" +#include "window/window.h" #include "threading/thread_ex.h" diff --git a/source/modules/asura-core/font/string.cpp b/source/modules/asura-core/font/string.cpp index 8c9c55a..72acaa6 100644 --- a/source/modules/asura-core/font/string.cpp +++ b/source/modules/asura-core/font/string.cpp @@ -1,376 +1,376 @@ -#include "String.hpp" -#include "Utf.hpp" - -namespace AsuraEngine -{ - namespace Text - { - - - //////////////////////////////////////////////////////////// - const std::size_t String::InvalidPos = std::basic_string<uint32>::npos; - - - //////////////////////////////////////////////////////////// - String::String() - { - } - - - //////////////////////////////////////////////////////////// - String::String(char ansiChar, const std::locale& locale) - { - mString += Utf32::DecodeAnsi(ansiChar, locale); - } - - - //////////////////////////////////////////////////////////// - String::String(wchar_t wideChar) - { - mString += Utf32::DecodeWide(wideChar); - } - - - //////////////////////////////////////////////////////////// - String::String(uint32 utf32Char) - { - mString += utf32Char; - } - - - //////////////////////////////////////////////////////////// - String::String(const char* ansiString, const std::locale& locale) - { - if (ansiString) - { - std::size_t length = strlen(ansiString); - if (length > 0) - { - mString.reserve(length + 1); - Utf32::FromAnsi(ansiString, ansiString + length, std::back_inserter(mString), locale); - } - } - } - - - //////////////////////////////////////////////////////////// - String::String(const std::string& ansiString, const std::locale& locale) - { - mString.reserve(ansiString.length() + 1); - Utf32::FromAnsi(ansiString.begin(), ansiString.end(), std::back_inserter(mString), locale); - } - - - //////////////////////////////////////////////////////////// - String::String(const wchar_t* wideString) - { - if (wideString) - { - std::size_t length = std::wcslen(wideString); - if (length > 0) - { - mString.reserve(length + 1); - Utf32::FromWide(wideString, wideString + length, std::back_inserter(mString)); - } - } - } - - - //////////////////////////////////////////////////////////// - String::String(const std::wstring& wideString) - { - mString.reserve(wideString.length() + 1); - Utf32::FromWide(wideString.begin(), wideString.end(), std::back_inserter(mString)); - } - - - //////////////////////////////////////////////////////////// - String::String(const uint32* utf32String) - { - if (utf32String) - mString = utf32String; - } - - - //////////////////////////////////////////////////////////// - String::String(const std::basic_string<uint32>& utf32String) : - mString(utf32String) - { - } - - - //////////////////////////////////////////////////////////// - String::String(const String& copy) : - mString(copy.mString) - { - } - - - //////////////////////////////////////////////////////////// - String::operator std::string() const - { - return ToAnsiString(); - } - - - //////////////////////////////////////////////////////////// - String::operator std::wstring() const - { - return ToWideString(); - } - - - //////////////////////////////////////////////////////////// - std::string String::ToAnsiString(const std::locale& locale) const - { - // Prepare the output string - std::string output; - output.reserve(mString.length() + 1); - - // Convert - Utf32::ToAnsi(mString.begin(), mString.end(), std::back_inserter(output), 0, locale); - - return output; - } - - - //////////////////////////////////////////////////////////// - std::wstring String::ToWideString() const - { - // Prepare the output string - std::wstring output; - output.reserve(mString.length() + 1); - - // Convert - Utf32::ToWide(mString.begin(), mString.end(), std::back_inserter(output), 0); - - return output; - } - - - //////////////////////////////////////////////////////////// - std::basic_string<uint8> String::ToUtf8() const - { - // Prepare the output string - std::basic_string<uint8> output; - output.reserve(mString.length()); - - // Convert - Utf32::ToUtf8(mString.begin(), mString.end(), std::back_inserter(output)); - - return output; - } - - - //////////////////////////////////////////////////////////// - std::basic_string<uint16> String::ToUtf16() const - { - // Prepare the output string - std::basic_string<uint16> output; - output.reserve(mString.length()); - - // Convert - Utf32::ToUtf16(mString.begin(), mString.end(), std::back_inserter(output)); - - return output; - } - - - //////////////////////////////////////////////////////////// - std::basic_string<uint32> String::ToUtf32() const - { - return mString; - } - - - //////////////////////////////////////////////////////////// - String& String::operator =(const String& right) - { - mString = right.mString; - return *this; - } - - - //////////////////////////////////////////////////////////// - String& String::operator +=(const String& right) - { - mString += right.mString; - return *this; - } - - - //////////////////////////////////////////////////////////// - uint32 String::operator [](std::size_t index) const - { - return mString[index]; - } - - - //////////////////////////////////////////////////////////// - uint32& String::operator [](std::size_t index) - { - return mString[index]; - } - - - //////////////////////////////////////////////////////////// - void String::Clear() - { - mString.clear(); - } - - - //////////////////////////////////////////////////////////// - std::size_t String::GetSize() const - { - return mString.size(); - } - - - //////////////////////////////////////////////////////////// - bool String::IsEmpty() const - { - return mString.empty(); - } - - - //////////////////////////////////////////////////////////// - void String::Erase(std::size_t position, std::size_t count) - { - mString.erase(position, count); - } - - - //////////////////////////////////////////////////////////// - void String::Insert(std::size_t position, const String& str) - { - mString.insert(position, str.mString); - } - - - //////////////////////////////////////////////////////////// - std::size_t String::Find(const String& str, std::size_t start) const - { - return mString.find(str.mString, start); - } - - - //////////////////////////////////////////////////////////// - void String::Replace(std::size_t position, std::size_t length, const String& replaceWith) - { - mString.replace(position, length, replaceWith.mString); - } - - - //////////////////////////////////////////////////////////// - void String::Replace(const String& searchFor, const String& replaceWith) - { - std::size_t step = replaceWith.GetSize(); - std::size_t len = searchFor.GetSize(); - std::size_t pos = Find(searchFor); - - // Replace each occurrence of search - while (pos != InvalidPos) - { - Replace(pos, len, replaceWith); - pos = Find(searchFor, pos + step); - } - } - - - //////////////////////////////////////////////////////////// - String String::Substring(std::size_t position, std::size_t length) const - { - return mString.substr(position, length); - } - - - //////////////////////////////////////////////////////////// - const uint32* String::GetData() const - { - return mString.c_str(); - } - - - //////////////////////////////////////////////////////////// - String::Iterator String::Begin() - { - return mString.begin(); - } - - - //////////////////////////////////////////////////////////// - String::ConstIterator String::Begin() const - { - return mString.begin(); - } - - - //////////////////////////////////////////////////////////// - String::Iterator String::End() - { - return mString.end(); - } - - - //////////////////////////////////////////////////////////// - String::ConstIterator String::End() const - { - return mString.end(); - } - - - //////////////////////////////////////////////////////////// - bool operator ==(const String& left, const String& right) - { - return left.mString == right.mString; - } - - - //////////////////////////////////////////////////////////// - bool operator !=(const String& left, const String& right) - { - return !(left == right); - } - - - //////////////////////////////////////////////////////////// - bool operator <(const String& left, const String& right) - { - return left.mString < right.mString; - } - - - //////////////////////////////////////////////////////////// - bool operator >(const String& left, const String& right) - { - return right < left; - } - - - //////////////////////////////////////////////////////////// - bool operator <=(const String& left, const String& right) - { - return !(right < left); - } - - - //////////////////////////////////////////////////////////// - bool operator >=(const String& left, const String& right) - { - return !(left < right); - } - - - //////////////////////////////////////////////////////////// - String operator +(const String& left, const String& right) - { - String string = left; - string += right; - - return string; - } - - - } -} +//#include "String.hpp" +//#include "Utf.hpp" +// +//namespace AsuraEngine +//{ +// namespace Text +// { +// +// +// //////////////////////////////////////////////////////////// +// const std::size_t String::InvalidPos = std::basic_string<uint32>::npos; +// +// +// //////////////////////////////////////////////////////////// +// String::String() +// { +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(char ansiChar, const std::locale& locale) +// { +// mString += Utf32::DecodeAnsi(ansiChar, locale); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(wchar_t wideChar) +// { +// mString += Utf32::DecodeWide(wideChar); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(uint32 utf32Char) +// { +// mString += utf32Char; +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const char* ansiString, const std::locale& locale) +// { +// if (ansiString) +// { +// std::size_t length = strlen(ansiString); +// if (length > 0) +// { +// mString.reserve(length + 1); +// Utf32::FromAnsi(ansiString, ansiString + length, std::back_inserter(mString), locale); +// } +// } +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const std::string& ansiString, const std::locale& locale) +// { +// mString.reserve(ansiString.length() + 1); +// Utf32::FromAnsi(ansiString.begin(), ansiString.end(), std::back_inserter(mString), locale); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const wchar_t* wideString) +// { +// if (wideString) +// { +// std::size_t length = std::wcslen(wideString); +// if (length > 0) +// { +// mString.reserve(length + 1); +// Utf32::FromWide(wideString, wideString + length, std::back_inserter(mString)); +// } +// } +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const std::wstring& wideString) +// { +// mString.reserve(wideString.length() + 1); +// Utf32::FromWide(wideString.begin(), wideString.end(), std::back_inserter(mString)); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const uint32* utf32String) +// { +// if (utf32String) +// mString = utf32String; +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const std::basic_string<uint32>& utf32String) : +// mString(utf32String) +// { +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const String& copy) : +// mString(copy.mString) +// { +// } +// +// +// //////////////////////////////////////////////////////////// +// String::operator std::string() const +// { +// return ToAnsiString(); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::operator std::wstring() const +// { +// return ToWideString(); +// } +// +// +// //////////////////////////////////////////////////////////// +// std::string String::ToAnsiString(const std::locale& locale) const +// { +// // Prepare the output string +// std::string output; +// output.reserve(mString.length() + 1); +// +// // Convert +// Utf32::ToAnsi(mString.begin(), mString.end(), std::back_inserter(output), 0, locale); +// +// return output; +// } +// +// +// //////////////////////////////////////////////////////////// +// std::wstring String::ToWideString() const +// { +// // Prepare the output string +// std::wstring output; +// output.reserve(mString.length() + 1); +// +// // Convert +// Utf32::ToWide(mString.begin(), mString.end(), std::back_inserter(output), 0); +// +// return output; +// } +// +// +// //////////////////////////////////////////////////////////// +// std::basic_string<uint8> String::ToUtf8() const +// { +// // Prepare the output string +// std::basic_string<uint8> output; +// output.reserve(mString.length()); +// +// // Convert +// Utf32::ToUtf8(mString.begin(), mString.end(), std::back_inserter(output)); +// +// return output; +// } +// +// +// //////////////////////////////////////////////////////////// +// std::basic_string<uint16> String::ToUtf16() const +// { +// // Prepare the output string +// std::basic_string<uint16> output; +// output.reserve(mString.length()); +// +// // Convert +// Utf32::ToUtf16(mString.begin(), mString.end(), std::back_inserter(output)); +// +// return output; +// } +// +// +// //////////////////////////////////////////////////////////// +// std::basic_string<uint32> String::ToUtf32() const +// { +// return mString; +// } +// +// +// //////////////////////////////////////////////////////////// +// String& String::operator =(const String& right) +// { +// mString = right.mString; +// return *this; +// } +// +// +// //////////////////////////////////////////////////////////// +// String& String::operator +=(const String& right) +// { +// mString += right.mString; +// return *this; +// } +// +// +// //////////////////////////////////////////////////////////// +// uint32 String::operator [](std::size_t index) const +// { +// return mString[index]; +// } +// +// +// //////////////////////////////////////////////////////////// +// uint32& String::operator [](std::size_t index) +// { +// return mString[index]; +// } +// +// +// //////////////////////////////////////////////////////////// +// void String::Clear() +// { +// mString.clear(); +// } +// +// +// //////////////////////////////////////////////////////////// +// std::size_t String::GetSize() const +// { +// return mString.size(); +// } +// +// +// //////////////////////////////////////////////////////////// +// bool String::IsEmpty() const +// { +// return mString.empty(); +// } +// +// +// //////////////////////////////////////////////////////////// +// void String::Erase(std::size_t position, std::size_t count) +// { +// mString.erase(position, count); +// } +// +// +// //////////////////////////////////////////////////////////// +// void String::Insert(std::size_t position, const String& str) +// { +// mString.insert(position, str.mString); +// } +// +// +// //////////////////////////////////////////////////////////// +// std::size_t String::Find(const String& str, std::size_t start) const +// { +// return mString.find(str.mString, start); +// } +// +// +// //////////////////////////////////////////////////////////// +// void String::Replace(std::size_t position, std::size_t length, const String& replaceWith) +// { +// mString.replace(position, length, replaceWith.mString); +// } +// +// +// //////////////////////////////////////////////////////////// +// void String::Replace(const String& searchFor, const String& replaceWith) +// { +// std::size_t step = replaceWith.GetSize(); +// std::size_t len = searchFor.GetSize(); +// std::size_t pos = Find(searchFor); +// +// // Replace each occurrence of search +// while (pos != InvalidPos) +// { +// Replace(pos, len, replaceWith); +// pos = Find(searchFor, pos + step); +// } +// } +// +// +// //////////////////////////////////////////////////////////// +// String String::Substring(std::size_t position, std::size_t length) const +// { +// return mString.substr(position, length); +// } +// +// +// //////////////////////////////////////////////////////////// +// const uint32* String::GetData() const +// { +// return mString.c_str(); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::Iterator String::Begin() +// { +// return mString.begin(); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::ConstIterator String::Begin() const +// { +// return mString.begin(); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::Iterator String::End() +// { +// return mString.end(); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::ConstIterator String::End() const +// { +// return mString.end(); +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator ==(const String& left, const String& right) +// { +// return left.mString == right.mString; +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator !=(const String& left, const String& right) +// { +// return !(left == right); +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator <(const String& left, const String& right) +// { +// return left.mString < right.mString; +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator >(const String& left, const String& right) +// { +// return right < left; +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator <=(const String& left, const String& right) +// { +// return !(right < left); +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator >=(const String& left, const String& right) +// { +// return !(left < right); +// } +// +// +// //////////////////////////////////////////////////////////// +// String operator +(const String& left, const String& right) +// { +// String string = left; +// string += right; +// +// return string; +// } +// +// +// } +//} diff --git a/source/modules/asura-core/font/string.hpp b/source/modules/asura-core/font/string.hpp index 226735b..5a48eb7 100644 --- a/source/modules/asura-core/font/string.hpp +++ b/source/modules/asura-core/font/string.hpp @@ -1,594 +1,595 @@ -#ifndef __ASURA_ENGINE_STRING_H__ -#define __ASURA_ENGINE_STRING_H__ - -#include "Config.h" -#include <iterator> -#include <locale> -#include <string> - -namespace AsuraEngine -{ - namespace Text - { - - - //////////////////////////////////////////////////////////// - /// \brief Utility string class that automatically handles - /// conversions between types and encodings - /// - //////////////////////////////////////////////////////////// - class String - { - public: - - //////////////////////////////////////////////////////////// - // Types - //////////////////////////////////////////////////////////// - typedef std::basic_string<uint32>::iterator Iterator; ///< Iterator type - typedef std::basic_string<uint32>::const_iterator ConstIterator; ///< Read-only iterator type - - //////////////////////////////////////////////////////////// - // Static member data - //////////////////////////////////////////////////////////// - static const std::size_t InvalidPos; ///< Represents an invalid position in the string - - //////////////////////////////////////////////////////////// - /// \brief Default constructor - /// - /// This constructor creates an empty string. - /// - //////////////////////////////////////////////////////////// - String(); - - //////////////////////////////////////////////////////////// - /// \brief Construct from a single ANSI character and a locale - /// - /// The source character is converted to UTF-32 according - /// to the given locale. - /// - /// \param ansiChar ANSI character to convert - /// \param locale Locale to use for conversion - /// - //////////////////////////////////////////////////////////// - String(char ansiChar, const std::locale& locale = std::locale()); - - //////////////////////////////////////////////////////////// - /// \brief Construct from single wide character - /// - /// \param wideChar Wide character to convert - /// - //////////////////////////////////////////////////////////// - String(wchar_t wideChar); - - //////////////////////////////////////////////////////////// - /// \brief Construct from single UTF-32 character - /// - /// \param utf32Char UTF-32 character to convert - /// - //////////////////////////////////////////////////////////// - String(uint utf32Char); - - //////////////////////////////////////////////////////////// - /// \brief Construct from a null-terminated C-style ANSI string and a locale - /// - /// The source string is converted to UTF-32 according - /// to the given locale. - /// - /// \param ansiString ANSI string to convert - /// \param locale Locale to use for conversion - /// - //////////////////////////////////////////////////////////// - String(const char* ansiString, const std::locale& locale = std::locale()); - - //////////////////////////////////////////////////////////// - /// \brief Construct from an ANSI string and a locale - /// - /// The source string is converted to UTF-32 according - /// to the given locale. - /// - /// \param ansiString ANSI string to convert - /// \param locale Locale to use for conversion - /// - //////////////////////////////////////////////////////////// - String(const std::string& ansiString, const std::locale& locale = std::locale()); - - //////////////////////////////////////////////////////////// - /// \brief Construct from null-terminated C-style wide string - /// - /// \param wideString Wide string to convert - /// - //////////////////////////////////////////////////////////// - String(const wchar_t* wideString); - - //////////////////////////////////////////////////////////// - /// \brief Construct from a wide string - /// - /// \param wideString Wide string to convert - /// - //////////////////////////////////////////////////////////// - String(const std::wstring& wideString); - - //////////////////////////////////////////////////////////// - /// \brief Construct from a null-terminated C-style UTF-32 string - /// - /// \param utf32String UTF-32 string to assign - /// - //////////////////////////////////////////////////////////// - String(const uint* utf32String); - - //////////////////////////////////////////////////////////// - /// \brief Construct from an UTF-32 string - /// - /// \param utf32String UTF-32 string to assign - /// - //////////////////////////////////////////////////////////// - String(const std::basic_string<uint>& utf32String); - - //////////////////////////////////////////////////////////// - /// \brief Copy constructor - /// - /// \param copy Instance to copy - /// - //////////////////////////////////////////////////////////// - String(const String& copy); - - //////////////////////////////////////////////////////////// - /// \brief Create a new sf::String from a UTF-8 encoded string - /// - /// \param begin Forward iterator to the beginning of the UTF-8 sequence - /// \param end Forward iterator to the end of the UTF-8 sequence - /// - /// \return A sf::String containing the source string - /// - /// \see fromUtf16, fromUtf32 - /// - //////////////////////////////////////////////////////////// - template <typename T> - static String FromUtf8(T begin, T end); - - //////////////////////////////////////////////////////////// - /// \brief Create a new sf::String from a UTF-16 encoded string - /// - /// \param begin Forward iterator to the beginning of the UTF-16 sequence - /// \param end Forward iterator to the end of the UTF-16 sequence - /// - /// \return A sf::String containing the source string - /// - /// \see fromUtf8, fromUtf32 - /// - //////////////////////////////////////////////////////////// - template <typename T> - static String FromUtf16(T begin, T end); - - //////////////////////////////////////////////////////////// - /// \brief Create a new sf::String from a UTF-32 encoded string - /// - /// This function is provided for consistency, it is equivalent to - /// using the constructors that takes a const sf::uint* or - /// a std::basic_string<sf::uint>. - /// - /// \param begin Forward iterator to the beginning of the UTF-32 sequence - /// \param end Forward iterator to the end of the UTF-32 sequence - /// - /// \return A sf::String containing the source string - /// - /// \see fromUtf8, fromUtf16 - /// - //////////////////////////////////////////////////////////// - template <typename T> - static String FromUtf32(T begin, T end); - - //////////////////////////////////////////////////////////// - /// \brief Implicit conversion operator to std::string (ANSI string) - /// - /// The current global locale is used for conversion. If you - /// want to explicitly specify a locale, see toAnsiString. - /// Characters that do not fit in the target encoding are - /// discarded from the returned string. - /// This operator is defined for convenience, and is equivalent - /// to calling toAnsiString(). - /// - /// \return Converted ANSI string - /// - /// \see toAnsiString, operator std::wstring - /// - //////////////////////////////////////////////////////////// - operator std::string() const; - - //////////////////////////////////////////////////////////// - /// \brief Implicit conversion operator to std::wstring (wide string) - /// - /// Characters that do not fit in the target encoding are - /// discarded from the returned string. - /// This operator is defined for convenience, and is equivalent - /// to calling toWideString(). - /// - /// \return Converted wide string - /// - /// \see toWideString, operator std::string - /// - //////////////////////////////////////////////////////////// - operator std::wstring() const; - - //////////////////////////////////////////////////////////// - /// \brief Convert the Unicode string to an ANSI string - /// - /// The UTF-32 string is converted to an ANSI string in - /// the encoding defined by \a locale. - /// Characters that do not fit in the target encoding are - /// discarded from the returned string. - /// - /// \param locale Locale to use for conversion - /// - /// \return Converted ANSI string - /// - /// \see toWideString, operator std::string - /// - //////////////////////////////////////////////////////////// - std::string ToAnsiString(const std::locale& locale = std::locale()) const; - - //////////////////////////////////////////////////////////// - /// \brief Convert the Unicode string to a wide string - /// - /// Characters that do not fit in the target encoding are - /// discarded from the returned string. - /// - /// \return Converted wide string - /// - /// \see toAnsiString, operator std::wstring - /// - //////////////////////////////////////////////////////////// - std::wstring ToWideString() const; - - //////////////////////////////////////////////////////////// - /// \brief Convert the Unicode string to a UTF-8 string - /// - /// \return Converted UTF-8 string - /// - /// \see toUtf16, toUtf32 - /// - //////////////////////////////////////////////////////////// - std::basic_string<uint8> ToUtf8() const; - - //////////////////////////////////////////////////////////// - /// \brief Convert the Unicode string to a UTF-16 string - /// - /// \return Converted UTF-16 string - /// - /// \see toUtf8, toUtf32 - /// - //////////////////////////////////////////////////////////// - std::basic_string<uint16> ToUtf16() const; - - //////////////////////////////////////////////////////////// - /// \brief Convert the Unicode string to a UTF-32 string - /// - /// This function doesn't perform any conversion, since the - /// string is already stored as UTF-32 internally. - /// - /// \return Converted UTF-32 string - /// - /// \see toUtf8, toUtf16 - /// - //////////////////////////////////////////////////////////// - std::basic_string<uint> ToUtf32() const; - - //////////////////////////////////////////////////////////// - /// \brief Overload of assignment operator - /// - /// \param right Instance to assign - /// - /// \return Reference to self - /// - //////////////////////////////////////////////////////////// - String& operator =(const String& right); - - //////////////////////////////////////////////////////////// - /// \brief Overload of += operator to append an UTF-32 string - /// - /// \param right String to append - /// - /// \return Reference to self - /// - //////////////////////////////////////////////////////////// - String& operator +=(const String& right); - - //////////////////////////////////////////////////////////// - /// \brief Overload of [] operator to access a character by its position - /// - /// This function provides read-only access to characters. - /// Note: the behavior is undefined if \a index is out of range. - /// - /// \param index Index of the character to get - /// - /// \return Character at position \a index - /// - //////////////////////////////////////////////////////////// - uint operator [](std::size_t index) const; - - //////////////////////////////////////////////////////////// - /// \brief Overload of [] operator to access a character by its position - /// - /// This function provides read and write access to characters. - /// Note: the behavior is undefined if \a index is out of range. - /// - /// \param index Index of the character to get - /// - /// \return Reference to the character at position \a index - /// - //////////////////////////////////////////////////////////// - uint& operator [](std::size_t index); - - //////////////////////////////////////////////////////////// - /// \brief Clear the string - /// - /// This function removes all the characters from the string. - /// - /// \see isEmpty, erase - /// - //////////////////////////////////////////////////////////// - void Clear(); - - //////////////////////////////////////////////////////////// - /// \brief Get the size of the string - /// - /// \return Number of characters in the string - /// - /// \see isEmpty - /// - //////////////////////////////////////////////////////////// - std::size_t GetSize() const; - - //////////////////////////////////////////////////////////// - /// \brief Check whether the string is empty or not - /// - /// \return True if the string is empty (i.e. contains no character) - /// - /// \see clear, getSize - /// - //////////////////////////////////////////////////////////// - bool IsEmpty() const; - - //////////////////////////////////////////////////////////// - /// \brief Erase one or more characters from the string - /// - /// This function removes a sequence of \a count characters - /// starting from \a position. - /// - /// \param position Position of the first character to erase - /// \param count Number of characters to erase - /// - //////////////////////////////////////////////////////////// - void Erase(std::size_t position, std::size_t count = 1); - - //////////////////////////////////////////////////////////// - /// \brief Insert one or more characters into the string - /// - /// This function inserts the characters of \a str - /// into the string, starting from \a position. - /// - /// \param position Position of insertion - /// \param str Characters to insert - /// - //////////////////////////////////////////////////////////// - void Insert(std::size_t position, const String& str); - - //////////////////////////////////////////////////////////// - /// \brief Find a sequence of one or more characters in the string - /// - /// This function searches for the characters of \a str - /// in the string, starting from \a start. - /// - /// \param str Characters to find - /// \param start Where to begin searching - /// - /// \return Position of \a str in the string, or String::InvalidPos if not found - /// - //////////////////////////////////////////////////////////// - std::size_t Find(const String& str, std::size_t start = 0) const; - - //////////////////////////////////////////////////////////// - /// \brief Replace a substring with another string - /// - /// This function replaces the substring that starts at index \a position - /// and spans \a length characters with the string \a replaceWith. - /// - /// \param position Index of the first character to be replaced - /// \param length Number of characters to replace. You can pass InvalidPos to - /// replace all characters until the end of the string. - /// \param replaceWith String that replaces the given substring. - /// - //////////////////////////////////////////////////////////// - void Replace(std::size_t position, std::size_t length, const String& replaceWith); - - //////////////////////////////////////////////////////////// - /// \brief Replace all occurrences of a substring with a replacement string - /// - /// This function replaces all occurrences of \a searchFor in this string - /// with the string \a replaceWith. - /// - /// \param searchFor The value being searched for - /// \param replaceWith The value that replaces found \a searchFor values - /// - //////////////////////////////////////////////////////////// - void Replace(const String& searchFor, const String& replaceWith); - - //////////////////////////////////////////////////////////// - /// \brief Return a part of the string - /// - /// This function returns the substring that starts at index \a position - /// and spans \a length characters. - /// - /// \param position Index of the first character - /// \param length Number of characters to include in the substring (if - /// the string is shorter, as many characters as possible - /// are included). \ref InvalidPos can be used to include all - /// characters until the end of the string. - /// - /// \return String object containing a substring of this object - /// - //////////////////////////////////////////////////////////// - String Substring(std::size_t position, std::size_t length = InvalidPos) const; - - //////////////////////////////////////////////////////////// - /// \brief Get a pointer to the C-style array of characters - /// - /// This functions provides a read-only access to a - /// null-terminated C-style representation of the string. - /// The returned pointer is temporary and is meant only for - /// immediate use, thus it is not recommended to store it. - /// - /// \return Read-only pointer to the array of characters - /// - //////////////////////////////////////////////////////////// - const uint* GetData() const; - - //////////////////////////////////////////////////////////// - /// \brief Return an iterator to the beginning of the string - /// - /// \return Read-write iterator to the beginning of the string characters - /// - /// \see end - /// - //////////////////////////////////////////////////////////// - Iterator Begin(); - - //////////////////////////////////////////////////////////// - /// \brief Return an iterator to the beginning of the string - /// - /// \return Read-only iterator to the beginning of the string characters - /// - /// \see end - /// - //////////////////////////////////////////////////////////// - ConstIterator Begin() const; - - //////////////////////////////////////////////////////////// - /// \brief Return an iterator to the end of the string - /// - /// The end iterator refers to 1 position past the last character; - /// thus it represents an invalid character and should never be - /// accessed. - /// - /// \return Read-write iterator to the end of the string characters - /// - /// \see begin - /// - //////////////////////////////////////////////////////////// - Iterator End(); - - //////////////////////////////////////////////////////////// - /// \brief Return an iterator to the end of the string - /// - /// The end iterator refers to 1 position past the last character; - /// thus it represents an invalid character and should never be - /// accessed. - /// - /// \return Read-only iterator to the end of the string characters - /// - /// \see begin - /// - //////////////////////////////////////////////////////////// - ConstIterator End() const; - - private: - - friend bool operator ==(const String& left, const String& right); - friend bool operator <(const String& left, const String& right); - - //////////////////////////////////////////////////////////// - // Member data - //////////////////////////////////////////////////////////// - std::basic_string<uint> mString; ///< Internal string of UTF-32 characters - }; - - //////////////////////////////////////////////////////////// - /// \relates String - /// \brief Overload of == operator to compare two UTF-32 strings - /// - /// \param left Left operand (a string) - /// \param right Right operand (a string) - /// - /// \return True if both strings are equal - /// - //////////////////////////////////////////////////////////// - bool operator ==(const String& left, const String& right); - - //////////////////////////////////////////////////////////// - /// \relates String - /// \brief Overload of != operator to compare two UTF-32 strings - /// - /// \param left Left operand (a string) - /// \param right Right operand (a string) - /// - /// \return True if both strings are different - /// - //////////////////////////////////////////////////////////// - bool operator !=(const String& left, const String& right); - - //////////////////////////////////////////////////////////// - /// \relates String - /// \brief Overload of < operator to compare two UTF-32 strings - /// - /// \param left Left operand (a string) - /// \param right Right operand (a string) - /// - /// \return True if \a left is lexicographically before \a right - /// - //////////////////////////////////////////////////////////// - bool operator <(const String& left, const String& right); - - //////////////////////////////////////////////////////////// - /// \relates String - /// \brief Overload of > operator to compare two UTF-32 strings - /// - /// \param left Left operand (a string) - /// \param right Right operand (a string) - /// - /// \return True if \a left is lexicographically after \a right - /// - //////////////////////////////////////////////////////////// - bool operator >(const String& left, const String& right); - - //////////////////////////////////////////////////////////// - /// \relates String - /// \brief Overload of <= operator to compare two UTF-32 strings - /// - /// \param left Left operand (a string) - /// \param right Right operand (a string) - /// - /// \return True if \a left is lexicographically before or equivalent to \a right - /// - //////////////////////////////////////////////////////////// - bool operator <=(const String& left, const String& right); - - //////////////////////////////////////////////////////////// - /// \relates String - /// \brief Overload of >= operator to compare two UTF-32 strings - /// - /// \param left Left operand (a string) - /// \param right Right operand (a string) - /// - /// \return True if \a left is lexicographically after or equivalent to \a right - /// - //////////////////////////////////////////////////////////// - bool operator >=(const String& left, const String& right); - - //////////////////////////////////////////////////////////// - /// \relates String - /// \brief Overload of binary + operator to concatenate two strings - /// - /// \param left Left operand (a string) - /// \param right Right operand (a string) - /// - /// \return Concatenated string - /// - //////////////////////////////////////////////////////////// - String operator +(const String& left, const String& right); - - #include "String.inl" - - } -} - -#endif
\ No newline at end of file +//#ifndef __ASURA_ENGINE_STRING_H__ +//#define __ASURA_ENGINE_STRING_H__ +// +//#include <asura-utils/type.h> +// +//#include <iterator> +//#include <locale> +//#include <string> +// +//namespace AsuraEngine +//{ +// namespace Text +// { +// +// +// //////////////////////////////////////////////////////////// +// /// \brief Utility string class that automatically handles +// /// conversions between types and encodings +// /// +// //////////////////////////////////////////////////////////// +// class String +// { +// public: +// +// //////////////////////////////////////////////////////////// +// // Types +// //////////////////////////////////////////////////////////// +// typedef std::basic_string<uint32>::iterator Iterator; ///< Iterator type +// typedef std::basic_string<uint32>::const_iterator ConstIterator; ///< Read-only iterator type +// +// //////////////////////////////////////////////////////////// +// // Static member data +// //////////////////////////////////////////////////////////// +// static const std::size_t InvalidPos; ///< Represents an invalid position in the string +// +// //////////////////////////////////////////////////////////// +// /// \brief Default constructor +// /// +// /// This constructor creates an empty string. +// /// +// //////////////////////////////////////////////////////////// +// String(); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from a single ANSI character and a locale +// /// +// /// The source character is converted to UTF-32 according +// /// to the given locale. +// /// +// /// \param ansiChar ANSI character to convert +// /// \param locale Locale to use for conversion +// /// +// //////////////////////////////////////////////////////////// +// String(char ansiChar, const std::locale& locale = std::locale()); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from single wide character +// /// +// /// \param wideChar Wide character to convert +// /// +// //////////////////////////////////////////////////////////// +// String(wchar_t wideChar); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from single UTF-32 character +// /// +// /// \param utf32Char UTF-32 character to convert +// /// +// //////////////////////////////////////////////////////////// +// String(uint utf32Char); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from a null-terminated C-style ANSI string and a locale +// /// +// /// The source string is converted to UTF-32 according +// /// to the given locale. +// /// +// /// \param ansiString ANSI string to convert +// /// \param locale Locale to use for conversion +// /// +// //////////////////////////////////////////////////////////// +// String(const char* ansiString, const std::locale& locale = std::locale()); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from an ANSI string and a locale +// /// +// /// The source string is converted to UTF-32 according +// /// to the given locale. +// /// +// /// \param ansiString ANSI string to convert +// /// \param locale Locale to use for conversion +// /// +// //////////////////////////////////////////////////////////// +// String(const std::string& ansiString, const std::locale& locale = std::locale()); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from null-terminated C-style wide string +// /// +// /// \param wideString Wide string to convert +// /// +// //////////////////////////////////////////////////////////// +// String(const wchar_t* wideString); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from a wide string +// /// +// /// \param wideString Wide string to convert +// /// +// //////////////////////////////////////////////////////////// +// String(const std::wstring& wideString); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from a null-terminated C-style UTF-32 string +// /// +// /// \param utf32String UTF-32 string to assign +// /// +// //////////////////////////////////////////////////////////// +// String(const uint* utf32String); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from an UTF-32 string +// /// +// /// \param utf32String UTF-32 string to assign +// /// +// //////////////////////////////////////////////////////////// +// String(const std::basic_string<uint>& utf32String); +// +// //////////////////////////////////////////////////////////// +// /// \brief Copy constructor +// /// +// /// \param copy Instance to copy +// /// +// //////////////////////////////////////////////////////////// +// String(const String& copy); +// +// //////////////////////////////////////////////////////////// +// /// \brief Create a new sf::String from a UTF-8 encoded string +// /// +// /// \param begin Forward iterator to the beginning of the UTF-8 sequence +// /// \param end Forward iterator to the end of the UTF-8 sequence +// /// +// /// \return A sf::String containing the source string +// /// +// /// \see fromUtf16, fromUtf32 +// /// +// //////////////////////////////////////////////////////////// +// template <typename T> +// static String FromUtf8(T begin, T end); +// +// //////////////////////////////////////////////////////////// +// /// \brief Create a new sf::String from a UTF-16 encoded string +// /// +// /// \param begin Forward iterator to the beginning of the UTF-16 sequence +// /// \param end Forward iterator to the end of the UTF-16 sequence +// /// +// /// \return A sf::String containing the source string +// /// +// /// \see fromUtf8, fromUtf32 +// /// +// //////////////////////////////////////////////////////////// +// template <typename T> +// static String FromUtf16(T begin, T end); +// +// //////////////////////////////////////////////////////////// +// /// \brief Create a new sf::String from a UTF-32 encoded string +// /// +// /// This function is provided for consistency, it is equivalent to +// /// using the constructors that takes a const sf::uint* or +// /// a std::basic_string<sf::uint>. +// /// +// /// \param begin Forward iterator to the beginning of the UTF-32 sequence +// /// \param end Forward iterator to the end of the UTF-32 sequence +// /// +// /// \return A sf::String containing the source string +// /// +// /// \see fromUtf8, fromUtf16 +// /// +// //////////////////////////////////////////////////////////// +// template <typename T> +// static String FromUtf32(T begin, T end); +// +// //////////////////////////////////////////////////////////// +// /// \brief Implicit conversion operator to std::string (ANSI string) +// /// +// /// The current global locale is used for conversion. If you +// /// want to explicitly specify a locale, see toAnsiString. +// /// Characters that do not fit in the target encoding are +// /// discarded from the returned string. +// /// This operator is defined for convenience, and is equivalent +// /// to calling toAnsiString(). +// /// +// /// \return Converted ANSI string +// /// +// /// \see toAnsiString, operator std::wstring +// /// +// //////////////////////////////////////////////////////////// +// operator std::string() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Implicit conversion operator to std::wstring (wide string) +// /// +// /// Characters that do not fit in the target encoding are +// /// discarded from the returned string. +// /// This operator is defined for convenience, and is equivalent +// /// to calling toWideString(). +// /// +// /// \return Converted wide string +// /// +// /// \see toWideString, operator std::string +// /// +// //////////////////////////////////////////////////////////// +// operator std::wstring() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Convert the Unicode string to an ANSI string +// /// +// /// The UTF-32 string is converted to an ANSI string in +// /// the encoding defined by \a locale. +// /// Characters that do not fit in the target encoding are +// /// discarded from the returned string. +// /// +// /// \param locale Locale to use for conversion +// /// +// /// \return Converted ANSI string +// /// +// /// \see toWideString, operator std::string +// /// +// //////////////////////////////////////////////////////////// +// std::string ToAnsiString(const std::locale& locale = std::locale()) const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Convert the Unicode string to a wide string +// /// +// /// Characters that do not fit in the target encoding are +// /// discarded from the returned string. +// /// +// /// \return Converted wide string +// /// +// /// \see toAnsiString, operator std::wstring +// /// +// //////////////////////////////////////////////////////////// +// std::wstring ToWideString() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Convert the Unicode string to a UTF-8 string +// /// +// /// \return Converted UTF-8 string +// /// +// /// \see toUtf16, toUtf32 +// /// +// //////////////////////////////////////////////////////////// +// std::basic_string<uint8> ToUtf8() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Convert the Unicode string to a UTF-16 string +// /// +// /// \return Converted UTF-16 string +// /// +// /// \see toUtf8, toUtf32 +// /// +// //////////////////////////////////////////////////////////// +// std::basic_string<uint16> ToUtf16() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Convert the Unicode string to a UTF-32 string +// /// +// /// This function doesn't perform any conversion, since the +// /// string is already stored as UTF-32 internally. +// /// +// /// \return Converted UTF-32 string +// /// +// /// \see toUtf8, toUtf16 +// /// +// //////////////////////////////////////////////////////////// +// std::basic_string<uint> ToUtf32() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Overload of assignment operator +// /// +// /// \param right Instance to assign +// /// +// /// \return Reference to self +// /// +// //////////////////////////////////////////////////////////// +// String& operator =(const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \brief Overload of += operator to append an UTF-32 string +// /// +// /// \param right String to append +// /// +// /// \return Reference to self +// /// +// //////////////////////////////////////////////////////////// +// String& operator +=(const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \brief Overload of [] operator to access a character by its position +// /// +// /// This function provides read-only access to characters. +// /// Note: the behavior is undefined if \a index is out of range. +// /// +// /// \param index Index of the character to get +// /// +// /// \return Character at position \a index +// /// +// //////////////////////////////////////////////////////////// +// uint operator [](std::size_t index) const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Overload of [] operator to access a character by its position +// /// +// /// This function provides read and write access to characters. +// /// Note: the behavior is undefined if \a index is out of range. +// /// +// /// \param index Index of the character to get +// /// +// /// \return Reference to the character at position \a index +// /// +// //////////////////////////////////////////////////////////// +// uint& operator [](std::size_t index); +// +// //////////////////////////////////////////////////////////// +// /// \brief Clear the string +// /// +// /// This function removes all the characters from the string. +// /// +// /// \see isEmpty, erase +// /// +// //////////////////////////////////////////////////////////// +// void Clear(); +// +// //////////////////////////////////////////////////////////// +// /// \brief Get the size of the string +// /// +// /// \return Number of characters in the string +// /// +// /// \see isEmpty +// /// +// //////////////////////////////////////////////////////////// +// std::size_t GetSize() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Check whether the string is empty or not +// /// +// /// \return True if the string is empty (i.e. contains no character) +// /// +// /// \see clear, getSize +// /// +// //////////////////////////////////////////////////////////// +// bool IsEmpty() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Erase one or more characters from the string +// /// +// /// This function removes a sequence of \a count characters +// /// starting from \a position. +// /// +// /// \param position Position of the first character to erase +// /// \param count Number of characters to erase +// /// +// //////////////////////////////////////////////////////////// +// void Erase(std::size_t position, std::size_t count = 1); +// +// //////////////////////////////////////////////////////////// +// /// \brief Insert one or more characters into the string +// /// +// /// This function inserts the characters of \a str +// /// into the string, starting from \a position. +// /// +// /// \param position Position of insertion +// /// \param str Characters to insert +// /// +// //////////////////////////////////////////////////////////// +// void Insert(std::size_t position, const String& str); +// +// //////////////////////////////////////////////////////////// +// /// \brief Find a sequence of one or more characters in the string +// /// +// /// This function searches for the characters of \a str +// /// in the string, starting from \a start. +// /// +// /// \param str Characters to find +// /// \param start Where to begin searching +// /// +// /// \return Position of \a str in the string, or String::InvalidPos if not found +// /// +// //////////////////////////////////////////////////////////// +// std::size_t Find(const String& str, std::size_t start = 0) const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Replace a substring with another string +// /// +// /// This function replaces the substring that starts at index \a position +// /// and spans \a length characters with the string \a replaceWith. +// /// +// /// \param position Index of the first character to be replaced +// /// \param length Number of characters to replace. You can pass InvalidPos to +// /// replace all characters until the end of the string. +// /// \param replaceWith String that replaces the given substring. +// /// +// //////////////////////////////////////////////////////////// +// void Replace(std::size_t position, std::size_t length, const String& replaceWith); +// +// //////////////////////////////////////////////////////////// +// /// \brief Replace all occurrences of a substring with a replacement string +// /// +// /// This function replaces all occurrences of \a searchFor in this string +// /// with the string \a replaceWith. +// /// +// /// \param searchFor The value being searched for +// /// \param replaceWith The value that replaces found \a searchFor values +// /// +// //////////////////////////////////////////////////////////// +// void Replace(const String& searchFor, const String& replaceWith); +// +// //////////////////////////////////////////////////////////// +// /// \brief Return a part of the string +// /// +// /// This function returns the substring that starts at index \a position +// /// and spans \a length characters. +// /// +// /// \param position Index of the first character +// /// \param length Number of characters to include in the substring (if +// /// the string is shorter, as many characters as possible +// /// are included). \ref InvalidPos can be used to include all +// /// characters until the end of the string. +// /// +// /// \return String object containing a substring of this object +// /// +// //////////////////////////////////////////////////////////// +// String Substring(std::size_t position, std::size_t length = InvalidPos) const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Get a pointer to the C-style array of characters +// /// +// /// This functions provides a read-only access to a +// /// null-terminated C-style representation of the string. +// /// The returned pointer is temporary and is meant only for +// /// immediate use, thus it is not recommended to store it. +// /// +// /// \return Read-only pointer to the array of characters +// /// +// //////////////////////////////////////////////////////////// +// const uint* GetData() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Return an iterator to the beginning of the string +// /// +// /// \return Read-write iterator to the beginning of the string characters +// /// +// /// \see end +// /// +// //////////////////////////////////////////////////////////// +// Iterator Begin(); +// +// //////////////////////////////////////////////////////////// +// /// \brief Return an iterator to the beginning of the string +// /// +// /// \return Read-only iterator to the beginning of the string characters +// /// +// /// \see end +// /// +// //////////////////////////////////////////////////////////// +// ConstIterator Begin() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Return an iterator to the end of the string +// /// +// /// The end iterator refers to 1 position past the last character; +// /// thus it represents an invalid character and should never be +// /// accessed. +// /// +// /// \return Read-write iterator to the end of the string characters +// /// +// /// \see begin +// /// +// //////////////////////////////////////////////////////////// +// Iterator End(); +// +// //////////////////////////////////////////////////////////// +// /// \brief Return an iterator to the end of the string +// /// +// /// The end iterator refers to 1 position past the last character; +// /// thus it represents an invalid character and should never be +// /// accessed. +// /// +// /// \return Read-only iterator to the end of the string characters +// /// +// /// \see begin +// /// +// //////////////////////////////////////////////////////////// +// ConstIterator End() const; +// +// private: +// +// friend bool operator ==(const String& left, const String& right); +// friend bool operator <(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// // Member data +// //////////////////////////////////////////////////////////// +// std::basic_string<uint> mString; ///< Internal string of UTF-32 characters +// }; +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of == operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if both strings are equal +// /// +// //////////////////////////////////////////////////////////// +// bool operator ==(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of != operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if both strings are different +// /// +// //////////////////////////////////////////////////////////// +// bool operator !=(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of < operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if \a left is lexicographically before \a right +// /// +// //////////////////////////////////////////////////////////// +// bool operator <(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of > operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if \a left is lexicographically after \a right +// /// +// //////////////////////////////////////////////////////////// +// bool operator >(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of <= operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if \a left is lexicographically before or equivalent to \a right +// /// +// //////////////////////////////////////////////////////////// +// bool operator <=(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of >= operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if \a left is lexicographically after or equivalent to \a right +// /// +// //////////////////////////////////////////////////////////// +// bool operator >=(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of binary + operator to concatenate two strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return Concatenated string +// /// +// //////////////////////////////////////////////////////////// +// String operator +(const String& left, const String& right); +// +// #include "String.inl" +// +// } +//} +// +//#endif
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/binding/_canvas.cpp b/source/modules/asura-core/graphics/binding/_canvas.cpp index 7927995..6728ff3 100644 --- a/source/modules/asura-core/graphics/binding/_canvas.cpp +++ b/source/modules/asura-core/graphics/binding/_canvas.cpp @@ -25,6 +25,7 @@ namespace AsuraEngine LUAX_IMPL_METHOD(Canvas, _SetSize) { LUAX_PREPARE(L, Canvas); + return 0; } @@ -33,12 +34,14 @@ namespace AsuraEngine { LUAX_PREPARE(L, Canvas); + return 0; } // canvas:Unbind() LUAX_IMPL_METHOD(Canvas, _Unbind) { LUAX_PREPARE(L, Canvas); + return 0; } diff --git a/source/modules/asura-core/graphics/binding/_color32.cpp b/source/modules/asura-core/graphics/binding/_color32.cpp index ad7dad5..f2f716a 100644 --- a/source/modules/asura-core/graphics/binding/_color32.cpp +++ b/source/modules/asura-core/graphics/binding/_color32.cpp @@ -27,6 +27,7 @@ namespace AsuraEngine LUAX_IMPL_METHOD(Color32, _ToColor) { LUAX_PREPARE(L, Color32); + return 0; } @@ -34,7 +35,7 @@ namespace AsuraEngine LUAX_IMPL_METHOD(Color32, _GetRed) { LUAX_PREPARE(L, Color32); - + return 0; } // color32:GetGreen() @@ -42,6 +43,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, Color32); + return 0; } // color32:GetBlue() @@ -49,6 +51,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, Color32); + return 0; } // color32:GetAlpha() @@ -56,6 +59,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, Color32); + return 0; } } diff --git a/source/modules/asura-core/graphics/binding/_shader.cpp b/source/modules/asura-core/graphics/binding/_shader.cpp index a06e54b..af6e981 100644 --- a/source/modules/asura-core/graphics/binding/_shader.cpp +++ b/source/modules/asura-core/graphics/binding/_shader.cpp @@ -36,12 +36,14 @@ namespace AsuraEngine { LUAX_STATE(L); + return 0; } // shader:Use() LUAX_IMPL_METHOD(Shader, _Use) { LUAX_PREPARE(L, Shader); + return 0; } @@ -49,6 +51,7 @@ namespace AsuraEngine LUAX_IMPL_METHOD(Shader, _Unuse) { LUAX_PREPARE(L, Shader); + return 0; } @@ -57,6 +60,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, Shader); + return 0; } // shader:HasUniform() @@ -64,6 +68,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, Shader); + return 0; } // shader:GetUniformLocation() @@ -71,6 +76,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, Shader); + return 0; } // shader:SetBuiltInUniforms() @@ -78,6 +84,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, Shader); + return 0; } // shader:SetUniformFloat() @@ -85,41 +92,42 @@ namespace AsuraEngine { LUAX_PREPARE(L, Shader); + return 0; } // shader:SetUniformTexture() LUAX_IMPL_METHOD(Shader, _SetUniformTexture) { LUAX_PREPARE(L, Shader); - + return 0; } // shader:SetUniformVector2() LUAX_IMPL_METHOD(Shader, _SetUniformVector2) { LUAX_PREPARE(L, Shader); - + return 0; } // shader:SetUniformVector3() LUAX_IMPL_METHOD(Shader, _SetUniformVector3) { LUAX_PREPARE(L, Shader); - + return 0; } // shader:SetUniformVector4() LUAX_IMPL_METHOD(Shader, _SetUniformVector4) { LUAX_PREPARE(L, Shader); - + return 0; } // shader:SetUniformColor() LUAX_IMPL_METHOD(Shader, _SetUniformColor) { LUAX_PREPARE(L, Shader); - + return 0; } } diff --git a/source/modules/asura-core/graphics/canvas.cpp b/source/modules/asura-core/graphics/canvas.cpp index 8b556d9..89be45c 100644 --- a/source/modules/asura-core/graphics/canvas.cpp +++ b/source/modules/asura-core/graphics/canvas.cpp @@ -6,8 +6,7 @@ namespace AsuraEngine { Canvas::Canvas() - : Texture() - , mWidth(0) + : mWidth(0) , mHeight(0) { glGenFramebuffers(1, &mFBO); @@ -27,15 +26,5 @@ namespace AsuraEngine glBindTexture(GL_TEXTURE_2D, current_tex); } - void Canvas::Bind() - { - - } - - void Canvas::Unbind() - { - - } - } }
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/color.cpp b/source/modules/asura-core/graphics/color.cpp index 4d3691e..9343939 100644 --- a/source/modules/asura-core/graphics/color.cpp +++ b/source/modules/asura-core/graphics/color.cpp @@ -35,13 +35,18 @@ namespace AsuraEngine a = c.a / 255.f; } - Color Color::operator *(const Color& c) + Color::~Color() { - r *= c.r; - g *= c.g; - b *= c.b; - a *= c.a; } + //Color Color::operator *(const Color& c) + //{ + // r *= c.r; + // g *= c.g; + // b *= c.b; + // a *= c.a; + + //} + } }
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/gl.cpp b/source/modules/asura-core/graphics/gl.cpp index 41d43a3..9ffe010 100644 --- a/source/modules/asura-core/graphics/gl.cpp +++ b/source/modules/asura-core/graphics/gl.cpp @@ -3,6 +3,8 @@ #include "../core_config.h" #include "gl.h" +using namespace AEMath; + namespace AsuraEngine { namespace Graphics @@ -23,5 +25,20 @@ namespace AsuraEngine { } + //------------------------------------------------------------------------------// + + void OpenGL::SetViewport(const Recti v) + { + glViewport(v.x, v.y, v.w, v.h); + state.viewport = v; + } + + Recti OpenGL::GetViewport() + { + return state.viewport; + } + + + } }
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/gl.h b/source/modules/asura-core/graphics/gl.h index bfc60ea..4d21a5a 100644 --- a/source/modules/asura-core/graphics/gl.h +++ b/source/modules/asura-core/graphics/gl.h @@ -1,7 +1,9 @@ #ifndef __ASURA_ENGINE_OPENGL_H__ #define __ASURA_ENGINE_OPENGL_H__ -#include "glad/glad.h" +#include <asura-utils/math/rect.hpp> + +#include <glad/glad.h> namespace AsuraEngine { @@ -11,7 +13,9 @@ namespace AsuraEngine class Profiler; /// - /// һЩopengl״̬١ + /// һЩopengl״̬١ڱ༭രڻ£һڶӦһhwndһhdcԼ + /// opengl contextʹwglMakeCurrent(hdc, glc)ָǰ̶߳Ⱦhdc + /// openglglcglм¼ľһ̵߳һڵһopenglĵ״̬ /// class OpenGL { @@ -19,6 +23,9 @@ namespace AsuraEngine OpenGL(); ~OpenGL(); + void SetViewport(const AEMath::Recti viewport); + AEMath::Recti GetViewport(); + private: friend class Profiler; @@ -28,6 +35,14 @@ namespace AsuraEngine /// static bool instantiated; + /// + /// ¼opengl״̬ + /// + struct + { + AEMath::Recti viewport; + } state; + }; /// diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp index bdd8c3d..2b274c2 100644 --- a/source/modules/asura-core/graphics/image.cpp +++ b/source/modules/asura-core/graphics/image.cpp @@ -18,7 +18,6 @@ namespace AsuraEngine { } - //\Ϣ bool Image::Refresh(DecodedData* data) { ASSERT(data); @@ -27,14 +26,22 @@ namespace AsuraEngine ASSERT(imgData); glBindTexture(GL_TEXTURE_2D, mTex); - imgData->Lock(); int width = imgData->width; int height = imgData->height; - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imgData->pixels); + TextureFormat tf = ConvertColorFormat(imgData->format); + glTexImage2D( + GL_TEXTURE_2D + , 0 + , tf.internalformat + , width, height + , 0 + , tf.externalformat + , tf.type + , imgData->pixels + ); mImageData = imgData; imgData->Unlock(); - glBindTexture(GL_TEXTURE_2D, 0); return true; diff --git a/source/modules/asura-core/graphics/image.h b/source/modules/asura-core/graphics/image.h index 30df8c0..7795c08 100644 --- a/source/modules/asura-core/graphics/image.h +++ b/source/modules/asura-core/graphics/image.h @@ -8,10 +8,11 @@ #include <asura-utils/stringmap.hpp> #include <asura-utils/manager.hpp> +#include "../image/image_data.h" + #include "texture.h" #include "color.h" #include "color32.h" -#include "image_data.h" #include "render_state.h" namespace AsuraEngine @@ -50,9 +51,8 @@ namespace AsuraEngine uint GetHeight(); Color32 GetPixel(uint x, uint y); - void Render(const RenderTarget* rt, const RenderState& state) override; - - void Render(const RenderTarget* rt, const Math::Rectf& quad, const RenderState& state) override; + void Render(const RenderTarget* rt, const RenderState& state) override {}; + void Render(const RenderTarget* rt, const Math::Rectf& quad, const RenderState& state) override {}; private: diff --git a/source/modules/asura-core/graphics/mesh2d.h b/source/modules/asura-core/graphics/mesh2d.h index 31d3629..226b9f6 100644 --- a/source/modules/asura-core/graphics/mesh2d.h +++ b/source/modules/asura-core/graphics/mesh2d.h @@ -16,6 +16,8 @@ namespace AsuraEngine { public: + LUAX_DECL_FACTORY(Mesh2D); + Mesh2D(); ~Mesh2D(); diff --git a/source/modules/asura-core/graphics/render_target.h b/source/modules/asura-core/graphics/render_target.h index b1a695a..0749cab 100644 --- a/source/modules/asura-core/graphics/render_target.h +++ b/source/modules/asura-core/graphics/render_target.h @@ -13,8 +13,6 @@ namespace AsuraEngine namespace Graphics { - class Drawable; - /// /// ɱΪȾĿ࣬ /// Canvas(RenderTexture) diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp index c0c6f75..f33fd1a 100644 --- a/source/modules/asura-core/graphics/shader.cpp +++ b/source/modules/asura-core/graphics/shader.cpp @@ -15,14 +15,14 @@ namespace AsuraEngine } - bool Shader::Load(const std::string& vertexShader, const std::string& fragmentShader) + bool Shader::Refresh(AEIO::DecodedData* db) { - + return false; } uint Shader::GetUniformLocation(const std::string& uniform) { - + return 0; } GLuint Shader::GetGLProgramHandle() @@ -45,11 +45,6 @@ namespace AsuraEngine } - void Shader::SetUniformFloat(uint loc, float value) - { - - } - void Shader::SetUniformTexture(uint loc, const Texture& texture) { diff --git a/source/modules/asura-core/graphics/sprite_batch.h b/source/modules/asura-core/graphics/sprite_batch.h index 3143f73..eb1c89c 100644 --- a/source/modules/asura-core/graphics/sprite_batch.h +++ b/source/modules/asura-core/graphics/sprite_batch.h @@ -16,6 +16,8 @@ namespace AsuraEngine { public: + LUAX_DECL_FACTORY(SpriteBatch); + SpriteBatch(); ~SpriteBatch(); diff --git a/source/modules/asura-core/graphics/texture.cpp b/source/modules/asura-core/graphics/texture.cpp index c260ce9..4db6ad3 100644 --- a/source/modules/asura-core/graphics/texture.cpp +++ b/source/modules/asura-core/graphics/texture.cpp @@ -22,5 +22,24 @@ namespace AsuraEngine return mTex; } + TextureFormat Texture::ConvertColorFormat(const ColorFormat& colorformat) + { + TextureFormat t; + switch (colorformat) + { + case COLOR_FORMAT_RGBA8: + t.internalformat = GL_RGBA8; + t.externalformat = GL_RGBA; + t.type = GL_UNSIGNED_BYTE; + break; + case COLOR_FORMAT_RGBA32F: + t.internalformat = GL_RGBA32F; + t.externalformat = GL_RGBA; + t.type = GL_FLOAT; + break; + } + return t; + } + } }
\ No newline at end of file diff --git a/source/modules/asura-core/graphics/texture.h b/source/modules/asura-core/graphics/texture.h index 02d3407..f19f3a7 100644 --- a/source/modules/asura-core/graphics/texture.h +++ b/source/modules/asura-core/graphics/texture.h @@ -42,6 +42,17 @@ namespace AsuraEngine }; /// + /// ʽGPUڲCPUⲿʽ + /// + struct TextureFormat + { + GLenum internalformat; // GPUڲʽ + + GLenum externalformat; // CPUⲿʽ + GLenum type; // ⲿʽÿchannelֵ + }; + + /// /// 2D࣬2d meshrender targetбʹáTextureȾԭϽǣϷ /// ϲԵѿϵΪEditorҲϽΪԭ㣬Ϊ /// 㡣 @@ -94,6 +105,13 @@ namespace AsuraEngine //----------------------------------------------------------------------------// + /// + /// תcolor formatΪtexture format + /// + TextureFormat ConvertColorFormat(const ColorFormat& colorformat); + + //----------------------------------------------------------------------------// + GLuint mTex; FilterMode mMinFilter; diff --git a/source/modules/asura-core/graphics/binding/_image_data.cpp b/source/modules/asura-core/image/binding/_image_data.cpp index ac9473b..ac9473b 100644 --- a/source/modules/asura-core/graphics/binding/_image_data.cpp +++ b/source/modules/asura-core/image/binding/_image_data.cpp diff --git a/source/modules/asura-core/image/binding/_image_decode_task.cpp b/source/modules/asura-core/image/binding/_image_decode_task.cpp new file mode 100644 index 0000000..76b544b --- /dev/null +++ b/source/modules/asura-core/image/binding/_image_decode_task.cpp @@ -0,0 +1,21 @@ +#include "../image_decode_task.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace Graphics + { + + LUAX_REGISTRY(ImageDecodeTask) + { + + } + + LUAX_POSTPROCESS(ImageDecodeTask) + { + + } + + } +} diff --git a/source/modules/asura-core/graphics/image_data.cpp b/source/modules/asura-core/image/image_data.cpp index 64f83a8..1a6d3a2 100644 --- a/source/modules/asura-core/graphics/image_data.cpp +++ b/source/modules/asura-core/image/image_data.cpp @@ -31,11 +31,6 @@ namespace AsuraEngine delete[] pixels; } - ImageData::operator bool() - { - return size > 0; - } - void ImageData::Decode(IO::DataBuffer& buffer) { for (ImageDecoder* decoder : ImageDecoders) @@ -50,7 +45,7 @@ namespace AsuraEngine Color ImageData::GetPixel(uint x, uint y) { - + return Color(); } void ImageData::Lock() diff --git a/source/modules/asura-core/graphics/image_data.h b/source/modules/asura-core/image/image_data.h index b9d656c..d9427d3 100644 --- a/source/modules/asura-core/graphics/image_data.h +++ b/source/modules/asura-core/image/image_data.h @@ -9,8 +9,8 @@ #include <asura-utils/threading/thread.h> #include <asura-utils/threading/mutex.h> -#include "texture.h" -#include "color.h" +#include "../graphics/texture.h" +#include "../graphics/color.h" namespace AsuraEngine { diff --git a/source/modules/asura-core/image/image_decode_task.cpp b/source/modules/asura-core/image/image_decode_task.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/image/image_decode_task.cpp diff --git a/source/modules/asura-core/graphics/image_decode_task.h b/source/modules/asura-core/image/image_decode_task.h index ec5ed49..15b0837 100644 --- a/source/modules/asura-core/graphics/image_decode_task.h +++ b/source/modules/asura-core/image/image_decode_task.h @@ -1,7 +1,7 @@ #ifndef __ASURA_IMAGE_DECODE_TASK_H__ #define __ASURA_IMAGE_DECODE_TASK_H__ -#include <asura-utils/threading/thread_task.h> +#include <asura-utils/threading/task.h> #include <asura-utils/scripting/portable.hpp> namespace AsuraEngine @@ -11,7 +11,7 @@ namespace AsuraEngine class ImageDecodeTask : public AEScripting::Portable<ImageDecodeTask> - , public AEThreading::ThreadTask + , public AEThreading::Task { public: diff --git a/source/modules/asura-core/graphics/image_decoder.h b/source/modules/asura-core/image/image_decoder.h index 869c82a..8b82d2b 100644 --- a/source/modules/asura-core/graphics/image_decoder.h +++ b/source/modules/asura-core/image/image_decoder.h @@ -10,12 +10,12 @@ namespace AsuraEngine namespace Graphics { - class ImageDecoder + ASURA_ABSTRACT class ImageDecoder { public: - ImageDecoder(); - virtual ~ImageDecoder(); + ImageDecoder() {}; + virtual ~ImageDecoder() {}; /// /// жڴǷñdecoderѹ diff --git a/source/modules/asura-core/graphics/png_decoder.cpp b/source/modules/asura-core/image/png_decoder.cpp index 80463d5..80463d5 100644 --- a/source/modules/asura-core/graphics/png_decoder.cpp +++ b/source/modules/asura-core/image/png_decoder.cpp diff --git a/source/modules/asura-core/graphics/png_decoder.h b/source/modules/asura-core/image/png_decoder.h index 6377940..6377940 100644 --- a/source/modules/asura-core/graphics/png_decoder.h +++ b/source/modules/asura-core/image/png_decoder.h diff --git a/source/modules/asura-core/graphics/stb_decoder.cpp b/source/modules/asura-core/image/stb_decoder.cpp index 9a14141..b19f28b 100644 --- a/source/modules/asura-core/graphics/stb_decoder.cpp +++ b/source/modules/asura-core/image/stb_decoder.cpp @@ -1,7 +1,9 @@ #include <asura-utils/exceptions/exception.h> #include "stb_decoder.h" -#include "stb/stb_image.h" + +#define STB_IMAGE_IMPLEMENTATION +#include <stb/stb_image.h> namespace AsuraEngine { @@ -49,11 +51,12 @@ namespace AsuraEngine imageData.Lock(); if (imageData.pixels) - delete[] imageData.pixels; + free(imageData.pixels); imageData.pixels = (byte*)data; imageData.format = format; - imageData.width = width; + imageData.width = width; imageData.height = height; + imageData.size = size; imageData.Unlock(); } diff --git a/source/modules/asura-core/graphics/stb_decoder.h b/source/modules/asura-core/image/stb_decoder.h index 76e70c3..76e70c3 100644 --- a/source/modules/asura-core/graphics/stb_decoder.h +++ b/source/modules/asura-core/image/stb_decoder.h diff --git a/source/modules/asura-core/mesh/mesh2d_data.cpp b/source/modules/asura-core/mesh/mesh2d_data.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/mesh/mesh2d_data.cpp diff --git a/source/modules/asura-core/mesh/mesh2d_data.h b/source/modules/asura-core/mesh/mesh2d_data.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/mesh/mesh2d_data.h diff --git a/source/modules/asura-core/threading/thread_ex.cpp b/source/modules/asura-core/threading/thread_ex.cpp index 334e58b..4883f90 100644 --- a/source/modules/asura-core/threading/thread_ex.cpp +++ b/source/modules/asura-core/threading/thread_ex.cpp @@ -8,6 +8,7 @@ namespace AsuraEngine int ThreadEx::Process() { + return 0; } void ThreadEx::RegisterModules() diff --git a/source/modules/asura-core/wnd/binding/_window.cpp b/source/modules/asura-core/window/binding/_window.cpp index eb92de8..e477408 100644 --- a/source/modules/asura-core/wnd/binding/_window.cpp +++ b/source/modules/asura-core/window/binding/_window.cpp @@ -1,4 +1,4 @@ -#include "../../graphics/image_data.h" +#include "../../image/image_data.h" #include "../window.h" @@ -7,7 +7,7 @@ using namespace AEGraphics; namespace AsuraEngine { - namespace Wnd + namespace Window { LUAX_REGISTRY(Window) diff --git a/source/modules/asura-core/wnd/window.cpp b/source/modules/asura-core/window/window.cpp index 174d04e..99433d5 100644 --- a/source/modules/asura-core/wnd/window.cpp +++ b/source/modules/asura-core/window/window.cpp @@ -8,7 +8,7 @@ namespace AsuraEngine { - namespace Wnd + namespace Window { Window::Window() @@ -23,17 +23,15 @@ namespace AsuraEngine } #define try_init_window(impl) \ - if (!mImpl) \ - { \ - try \ + if (!mImpl) \ { \ - mImpl = new impl(config); \ - } \ - catch (Exception& e) \ - { \ - mImpl = nullptr; \ - } \ - } + mImpl = new impl(); \ + if (!mImpl->Init(config)) \ + { \ + delete mImpl; \ + mImpl = nullptr; \ + } \ + } bool Window::Init(const WindowConfig& config) { @@ -41,7 +39,7 @@ namespace AsuraEngine #if ASURA_WINDOW_SDL try_init_window(WindowImplSDL); #endif - ASSERT(mImpl); + return mImpl != nullptr; } void Window::Exit() @@ -83,7 +81,7 @@ namespace AsuraEngine void Window::Clear(const AEGraphics::Color& col /*= AEGraphics::Color::Black*/) { ASSERT(mImpl); - + glClearColor(col.r, col.g, col.b, col.a); } void Window::Clear(const Math::Recti& quad, const AEGraphics::Color& col /*= AEGraphics::Color::Black*/) diff --git a/source/modules/asura-core/wnd/window.h b/source/modules/asura-core/window/window.h index eb8a574..8ce0e64 100644 --- a/source/modules/asura-core/wnd/window.h +++ b/source/modules/asura-core/window/window.h @@ -11,7 +11,7 @@ namespace AsuraEngine { - namespace Wnd + namespace Window { class WindowImpl; @@ -21,22 +21,22 @@ namespace AsuraEngine /// enum WindowFlag { - WINDOW_FULLSCREEN = 1 << 1, /**< fullscreen window */ - WINDOW_OPENGL = 1 << 2, /**< window usable with OpenGL context */ - WINDOW_SHOWN = 1 << 3, /**< window is visible */ - WINDOW_HIDDEN = 1 << 4, /**< window is not visible */ - WINDOW_BORDERLESS = 1 << 5, /**< no window decoration */ - WINDOW_RESIZABLE = 1 << 6, /**< window can be resized */ - WINDOW_MINIMIZED = 1 << 7, /**< window is minimized */ - WINDOW_MAXIMIZED = 1 << 8, /**< window is maximized */ - WINDOW_INPUT_GRABBED = 1 << 9, /**< window has grabbed input focus */ - WINDOW_INPUT_FOCUS = 1 << 10, /**< window has input focus */ - WINDOW_MOUSE_FOCUS = 1 << 11, /**< window has mouse focus */ - WINDOW_ALLOW_HIGHDPI = 1 << 12, /**< window should be created in high-DPI mode if supported. - On macOS NSHighResolutionCapable must be set true in the - application's Info.plist for this to have any effect. */ - WINDOW_MOUSE_CAPTURE = 1 << 13, /**< window has mouse captured (unrelated to INPUT_GRABBED) */ - WINDOW_ALWAYS_ON_TOP = 1 << 14, /**< window should always be above others */ + WINDOW_FULLSCREEN = 1 << 1, ///< fullscreen window + WINDOW_OPENGL = 1 << 2, ///< window usable with OpenGL context + WINDOW_SHOWN = 1 << 3, ///< window is visible + WINDOW_HIDDEN = 1 << 4, ///< window is not visible + WINDOW_BORDERLESS = 1 << 5, ///< no window decoration + WINDOW_RESIZABLE = 1 << 6, ///< window can be resized + WINDOW_MINIMIZED = 1 << 7, ///< window is minimized + WINDOW_MAXIMIZED = 1 << 8, ///< window is maximized + WINDOW_INPUT_GRABBED = 1 << 9, ///< window has grabbed input focus + WINDOW_INPUT_FOCUS = 1 << 10, ///< window has input focus + WINDOW_MOUSE_FOCUS = 1 << 11, ///< window has mouse focus + WINDOW_ALLOW_HIGHDPI = 1 << 12, ///< window should be created in high-DPI mode if supported. + ///< On macOS NSHighResolutionCapable must be set true in the + ///< application's Info.plist for this to have any effect. + WINDOW_MOUSE_CAPTURE = 1 << 13, ///< window has mouse captured (unrelated to INPUT_GRABBED) + WINDOW_ALWAYS_ON_TOP = 1 << 14, ///< window should always be above others }; /// @@ -130,6 +130,8 @@ namespace AsuraEngine WindowImpl() {}; virtual ~WindowImpl() {}; + virtual bool Init(const WindowConfig& config); + virtual void SetSize(uint width, uint height) = 0; virtual void SetPosition(int x, int y) = 0; virtual void SetTitils(const std::string& title) = 0; @@ -144,6 +146,6 @@ namespace AsuraEngine } } -namespace AEWnd = AsuraEngine::Wnd; +namespace AEWindow = AsuraEngine::Window; #endif
\ No newline at end of file diff --git a/source/modules/asura-core/window/window_impl_glew.cpp b/source/modules/asura-core/window/window_impl_glew.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/window/window_impl_glew.cpp diff --git a/source/modules/asura-core/window/window_impl_glew.h b/source/modules/asura-core/window/window_impl_glew.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/window/window_impl_glew.h diff --git a/source/modules/asura-core/window/window_impl_glut.cpp b/source/modules/asura-core/window/window_impl_glut.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/window/window_impl_glut.cpp diff --git a/source/modules/asura-core/window/window_impl_glut.h b/source/modules/asura-core/window/window_impl_glut.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/source/modules/asura-core/window/window_impl_glut.h diff --git a/source/modules/asura-core/wnd/window_impl_sdl.cpp b/source/modules/asura-core/window/window_impl_sdl.cpp index e608b8b..9554e37 100644 --- a/source/modules/asura-core/wnd/window_impl_sdl.cpp +++ b/source/modules/asura-core/window/window_impl_sdl.cpp @@ -12,21 +12,32 @@ using namespace AEGraphics; namespace AsuraEngine { - namespace Wnd + namespace Window { #define asura_flag_to_sdl_flag(flag, _flag, _sdl_flag) \ if ((flag & _flag) != 0) \ flag |= _sdl_flag - WindowImplSDL::WindowImplSDL(const WindowConfig& config) + WindowImplSDL::WindowImplSDL() : mWnd(nullptr) , mGLContext(0) { + } + + WindowImplSDL::~WindowImplSDL() + { + SDL_GL_DeleteContext(mGLContext); + SDL_DestroyWindow(mWnd); + SDL_FlushEvent(SDL_WINDOWEVENT); + } + + bool WindowImplSDL::Init(const WindowConfig& config) + { if (SDL_Init(SDL_INIT_VIDEO) < 0) - throw Exception("Cant init sdl video."); + return false; - int flag = 0x0; + int flag = 0; asura_flag_to_sdl_flag(flag, WINDOW_FULLSCREEN, SDL_WINDOW_FULLSCREEN); asura_flag_to_sdl_flag(flag, WINDOW_OPENGL, SDL_WINDOW_OPENGL); asura_flag_to_sdl_flag(flag, WINDOW_SHOWN, SDL_WINDOW_SHOWN); @@ -56,8 +67,8 @@ namespace AsuraEngine mWnd = SDL_CreateWindow(config.title.c_str(), config.x, config.y, config.width, config.height, flag); if (!mWnd) - throw Exception("Cant create SDL window."); - + return false; + // ͼ try { @@ -72,13 +83,13 @@ namespace AsuraEngine int w = img->width, h = img->height; surface = SDL_CreateRGBSurfaceFrom( - img->pixels, - w, h, - 32, - w * 4, - Color32::RMASK, - Color32::GMASK, - Color32::BMASK, + img->pixels, + w, h, + 32, + w * 4, + Color32::RMASK, + Color32::GMASK, + Color32::BMASK, Color32::AMASK ); @@ -88,7 +99,8 @@ namespace AsuraEngine SDL_FreeSurface(surface); } } - } catch (...) + } + catch (...) { } @@ -97,18 +109,13 @@ namespace AsuraEngine if (!mGLContext) { SDL_DestroyWindow(mWnd); - throw Exception("Cant create SDL GL Context."); + return false; } SDL_GL_MakeCurrent(mWnd, mGLContext); SDL_GL_SetSwapInterval(config.vsync ? 1 : 0); - } - WindowImplSDL::~WindowImplSDL() - { - SDL_GL_DeleteContext(mGLContext); - SDL_DestroyWindow(mWnd); - SDL_FlushEvent(SDL_WINDOWEVENT); + return true; } void WindowImplSDL::SetSize(uint width, uint height) diff --git a/source/modules/asura-core/wnd/window_impl_sdl.h b/source/modules/asura-core/window/window_impl_sdl.h index 0e81c0a..de4cafb 100644 --- a/source/modules/asura-core/wnd/window_impl_sdl.h +++ b/source/modules/asura-core/window/window_impl_sdl.h @@ -11,16 +11,18 @@ namespace AsuraEngine { - namespace Wnd + namespace Window { class WindowImplSDL ASURA_FINAL : public WindowImpl { public: - WindowImplSDL(const WindowConfig& config); + WindowImplSDL(); ~WindowImplSDL(); + bool Init(const WindowConfig& config); + void SetSize(uint width, uint height) override; void SetPosition(int x, int y) override; void SetTitils(const std::string& title) override; diff --git a/source/modules/asura-utils/io/renewable.h b/source/modules/asura-utils/io/renewable.h index 769bdf6..282106d 100644 --- a/source/modules/asura-utils/io/renewable.h +++ b/source/modules/asura-utils/io/renewable.h @@ -17,8 +17,8 @@ namespace AsuraEngine ASURA_ABSTRACT class Renewable { public: - Renewable(); - virtual ~ Renewable(); + Renewable() {}; + virtual ~Renewable() {}; /// /// ̳RenewableҪṩһRefresh diff --git a/source/modules/asura-utils/math/rect.hpp b/source/modules/asura-utils/math/rect.hpp index 1751634..282b606 100644 --- a/source/modules/asura-utils/math/rect.hpp +++ b/source/modules/asura-utils/math/rect.hpp @@ -11,7 +11,8 @@ namespace AsuraEngine { public: Rect(); - ~Rect(T x, T y, T w, T h); + Rect(T x, T y, T w, T h); + ~Rect(); /// /// x,yǷrectڡ diff --git a/source/modules/asura-utils/math/vector2.hpp b/source/modules/asura-utils/math/vector2.hpp index df78255..4baf132 100644 --- a/source/modules/asura-utils/math/vector2.hpp +++ b/source/modules/asura-utils/math/vector2.hpp @@ -15,7 +15,7 @@ namespace AsuraEngine template <typename U> explicit Vector2(const Vector2<U>& vector); - Set(T X, T Y); + void Set(T X, T Y); T x; ///< X coordinate of the vector T y; ///< Y coordinate of the vector diff --git a/source/modules/asura-utils/math/vector2.inl b/source/modules/asura-utils/math/vector2.inl index 9e131a7..155432a 100644 --- a/source/modules/asura-utils/math/vector2.inl +++ b/source/modules/asura-utils/math/vector2.inl @@ -23,7 +23,7 @@ inline Vector2<T>::Vector2(const Vector2<U>& vector) : } template <typename T> -inline Vector2<T>::Set(T X, T Y) +inline void Vector2<T>::Set(T X, T Y) { x = X; y = Y; diff --git a/source/modules/asura-utils/math/vector4.inl b/source/modules/asura-utils/math/vector4.inl index 025bfcc..4b043a1 100644 --- a/source/modules/asura-utils/math/vector4.inl +++ b/source/modules/asura-utils/math/vector4.inl @@ -14,11 +14,11 @@ inline Vector4<T>::Vector4() : //////////////////////////////////////////////////////////// template <typename T> -inline Vector4<T>::Vector4(T X, T Y, T Z) : +inline Vector4<T>::Vector4(T X, T Y, T Z, T W) : x(X), y(Y), z(Z), - w(0) + w(W) { } @@ -30,7 +30,7 @@ template <typename U> inline Vector4<T>::Vector4(const Vector4<U>& vector) : x(static_cast<T>(vector.x)), y(static_cast<T>(vector.y)), - z(static_cast<T>(vector.z)) + z(static_cast<T>(vector.z)), w(static_cast<T>(vector.w)) { } diff --git a/source/modules/asura-utils/stringmap.hpp b/source/modules/asura-utils/stringmap.hpp index ddba128..8d8f231 100644 --- a/source/modules/asura-utils/stringmap.hpp +++ b/source/modules/asura-utils/stringmap.hpp @@ -16,11 +16,11 @@ namespace AsuraEngine bool ContainsKey(const key_type& key); - bool ContainsString(const String& str); + bool ContainsString(const std::string& str); std::string GetStringByKey(const key_type& key); - key_type GetKeyByString(const String& str); + key_type GetKeyByString(const std::string& str); }; diff --git a/source/tests/win32/01-window/02_multi_window.cpp b/source/tests/win32/01-window/02_multi_window.cpp index 99a943f..0237fc9 100644 --- a/source/tests/win32/01-window/02_multi_window.cpp +++ b/source/tests/win32/01-window/02_multi_window.cpp @@ -52,7 +52,13 @@ LONG WINAPI WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { break; case WM_PAINT: wglMakeCurrent(windowData->deviceContext, windowData->renderContext); - glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_TRIANGLES); glVertex2i(0, 1); glVertex2i(-1, -1); glVertex2i(1, -1); glEnd(); glFlush(); + glClear(GL_COLOR_BUFFER_BIT); + glBegin(GL_TRIANGLES); + glVertex2i(0, 1); + glVertex2i(-1, -1); + glVertex2i(1, -1); + glEnd(); + glFlush(); wglMakeCurrent(NULL, NULL); BeginPaint(hWnd, &ps); EndPaint(hWnd, &ps); return 0; @@ -91,10 +97,10 @@ int WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPT wc.lpszClassName = "OpenGL2"; RegisterClass(&wc); - hWnd = CreateWindowEx(WS_EX_WINDOWEDGE,"OpenGL2", "Hi there", WS_VSCROLL|WS_TILEDWINDOW, 0, 0, 640, 480, NULL, NULL, hInstance, NULL); - //hWnd2 = CreateWindow("OpenGL2", "Hi there", WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 110, 110, 640, 480, NULL, NULL, hInstance, NULL); + hWnd = CreateWindow("OpenGL2", "Hi there", WS_VSCROLL|WS_TILEDWINDOW, 0, 0, 640, 480, NULL, NULL, hInstance, NULL); + hWnd2 = CreateWindow("OpenGL2", "Hi there", WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 110, 110, 640, 480, NULL, NULL, hInstance, NULL); ShowWindow(hWnd, nCmdShow); - //ShowWindow(hWnd2, nCmdShow); + ShowWindow(hWnd2, nCmdShow); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } wglMakeCurrent(NULL, NULL); DestroyWindow(hWnd); diff --git a/source/tests/win32/01-window/03_sub_menu.cpp b/source/tests/win32/01-window/03_sub_menu.cpp index 848c82e..bd3f7b6 100644 --- a/source/tests/win32/01-window/03_sub_menu.cpp +++ b/source/tests/win32/01-window/03_sub_menu.cpp @@ -1,9 +1,14 @@ #include "config.h" #if _run_app == _sub_menu -#include <windows.h> -#include <GL/gl.h> -#include <GL/glu.h> +#include <asura-utils/io/file_system.h> +#include <asura-utils/io/data_buffer.h> +#include <asura-core/graphics/image.h> +#include <asura-core/image/image_data.h> +#include <SDL2/SDL.h> + +using namespace AEIO; +using namespace AEGraphics; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); void AddMenus(HWND); @@ -16,9 +21,10 @@ void AddMenus(HWND); #define IDM_ASSET 20 -int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, - PWSTR lpCmdLine, int nCmdShow) { +int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nCmdShow) +{ + AEIO::Filesystem::Get()->Init("D:\Asura\bin\win64"); MSG msg; WNDCLASSW wc = { 0 }; wc.lpszClassName = L"Submenu"; @@ -28,9 +34,9 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, wc.hCursor = LoadCursor(0, IDC_ARROW); RegisterClassW(&wc); - CreateWindowW(wc.lpszClassName, L"The Incredible Asura", + CreateWindowW(wc.lpszClassName, L"Asura v0.1", WS_OVERLAPPEDWINDOW | WS_VISIBLE, - 100, 100, 350, 250, 0, 0, hInstance, 0); + 200, 200, 550, 450, 0, 0, hInstance, 0); while (GetMessage(&msg, NULL, 0, 0)) { @@ -51,6 +57,11 @@ HPEN hPen; HPEN hOldPen; PIXELFORMATDESCRIPTOR pfd; int pf; +File* file; +DataBuffer db(102400); +AEIO::Filesystem* fs; +ImageData* imgdata = new ImageData(); +Image* img; LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { @@ -61,8 +72,6 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, AddMenus(hwnd); hdc = GetDC(hwnd); - glc = wglCreateContext(hdc); - memset(&pfd, 0, sizeof(pfd)); pfd.nSize = sizeof(pfd); pfd.nVersion = 1; @@ -73,10 +82,28 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, pf = ChoosePixelFormat(hdc, &pfd); SetPixelFormat(hdc, pf, &pfd); DescribePixelFormat(hdc, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd); - ReleaseDC(hwnd, hdc); + //ReleaseDC(hwnd, hdc); + //glc = wglCreateContext(hdc); glc = wglCreateContext(hdc); + + // ͼƬ + fs = AEIO::Filesystem::Get(); + fs->Mount(".", "root"); + file = new File("root/img.png"); + file->Open(File::FILE_MODE_READ); + file->ReadAll(&db); + wglMakeCurrent(hdc, glc); + if (!gladLoadGL()) + { + return 0; + } + + imgdata->Decode(db); + img = new Image(); + img->Refresh(imgdata); + break; case WM_COMMAND: @@ -102,22 +129,38 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, case WM_PAINT: - //hdc = BeginPaint(hwnd, &ps); - //hPen = CreatePen(PS_SOLID, 1, RGB(255, 0, 0)); - //hOldPen = (HPEN)SelectObject(hdc, hPen); - //hBrush = CreateSolidBrush(RGB(0, 0, 255)); - //hOldBrush = (HBRUSH)SelectObject(hdc, hBrush); - //Rectangle(hdc, 100, 100, 200, 170); - //EndPaint(hwnd, &ps); - hdc = GetDC(hwnd); - glc = wglCreateContext(hdc); - wglMakeCurrent(hdc, glc); + //hdc = GetDC(hwnd); + //glc = wglCreateContext(hdc); glClearColor(0.16, 0.16, 0.16, 1); - glClear(GL_COLOR_BUFFER_BIT); glColor4f(0.219, 0.219, 0.219, 1); - glRectf(-0.5f, -0.5f, 0.5f, 0.5f); //ƾ - glFlush(); //ִOpenGLָбеָ - wglMakeCurrent(NULL, NULL); + //glRectf(-0.5f, -0.5f, 0.5f, 0.5f); + glColor4f( 1, 1, 1, 1); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + GLint tex = img->GetGLTextureHandle(); + + glBindTexture(GL_TEXTURE_2D, tex); // + glEnable(GL_TEXTURE_2D); //2Dӳ + + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //Sͼ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //Tͼ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); //Ŵ˷ʽ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); //С˷ʽ + + + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, 0.0f); + glTexCoord2f(1.0f, 0.0f); + glVertex3f(0.5f, -0.5f, 0.0f); + glTexCoord2f(1.0f, 1.0f); + glVertex3f(1.0f, 1.0f, 0.0f); + glTexCoord2f(0.0f, 1.0f); + glVertex3f(-0.5f, 0.5f, 0.0f); + glEnd(); + + glFlush(); BeginPaint(hwnd, &ps); EndPaint(hwnd, &ps); break; } |