Format codes
This commit is contained in:
parent
1e12296181
commit
4aa8a549aa
|
|
@ -0,0 +1,108 @@
|
|||
# Clang-format version v9.0.0
|
||||
---
|
||||
Language: Cpp
|
||||
BasedOnStyle: Google
|
||||
|
||||
ColumnLimit: 120
|
||||
|
||||
##
|
||||
## Indent Style
|
||||
##
|
||||
|
||||
IndentWidth: 4
|
||||
AccessModifierOffset: -4
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
||||
IndentCaseLabels: false
|
||||
NamespaceIndentation: None
|
||||
|
||||
##
|
||||
## Align Style
|
||||
##
|
||||
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: true
|
||||
AlignConsecutiveDeclarations: true
|
||||
AlignEscapedNewlinesLeft: true
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
PointerAlignment: Left
|
||||
|
||||
##
|
||||
## SingleLine Style
|
||||
##
|
||||
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: Empty
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: true
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BreakBeforeBraces: Allman
|
||||
BraceWrapping:
|
||||
AfterClass: true
|
||||
AfterControlStatement: true
|
||||
AfterEnum: true
|
||||
AfterFunction: true
|
||||
AfterNamespace: true
|
||||
AfterObjCDeclaration: true
|
||||
AfterStruct: true
|
||||
AfterUnion: true
|
||||
BeforeCatch: true
|
||||
BeforeElse: true
|
||||
IndentBraces: true
|
||||
BreakBeforeBinaryOperators: NonAssignment
|
||||
BreakBeforeTernaryOperators: true
|
||||
CommentPragmas: "^ IWYU pragma:"
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
|
||||
##
|
||||
## Others
|
||||
##
|
||||
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
BreakInheritanceList: BeforeComma
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
Cpp11BracedListStyle: false
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
ForEachMacros: [foreach, Q_FOREACH, BOOST_FOREACH]
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
Priority: 2
|
||||
- Regex: '^(<|"(gtest|isl|json)/)'
|
||||
Priority: 3
|
||||
- Regex: ".*"
|
||||
Priority: 1
|
||||
IndentWrappedFunctionNames: false
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
MacroBlockBegin: ""
|
||||
MacroBlockEnd: ""
|
||||
MaxEmptyLinesToKeep: 1
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 2
|
||||
SpacesInAngles: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Cpp11
|
||||
|
|
@ -14,7 +14,7 @@ insert_final_newline = true
|
|||
charset = gb2312
|
||||
|
||||
# 4 space indentation
|
||||
indent_style = tab
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
# Matches the exact files
|
||||
|
|
|
|||
|
|
@ -65,13 +65,13 @@
|
|||
<ClInclude Include="..\..\src\kiwano\platform\Window.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\Brush.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\Color.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\dx\D2DDeviceResources.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\dx\D3D10DeviceResources.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\dx\D3D11DeviceResources.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\dx\D3DDeviceResourcesBase.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\dx\FontCollectionLoader.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\dx\helper.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\dx\TextRenderer.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\D2DDeviceResources.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\D3D10DeviceResources.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\D3D11DeviceResources.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\D3DDeviceResourcesBase.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\FontCollectionLoader.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\helper.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\TextRenderer.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\Font.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\Geometry.h" />
|
||||
<ClInclude Include="..\..\src\kiwano\render\GeometrySink.h" />
|
||||
|
|
@ -136,11 +136,11 @@
|
|||
<ClCompile Include="..\..\src\kiwano\platform\Window.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\Brush.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\Color.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\dx\D2DDeviceResources.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\dx\D3D10DeviceResources.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\dx\D3D11DeviceResources.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\dx\FontCollectionLoader.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\dx\TextRenderer.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\DirectX\D2DDeviceResources.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\DirectX\D3D10DeviceResources.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\DirectX\D3D11DeviceResources.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\DirectX\FontCollectionLoader.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\DirectX\TextRenderer.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\Font.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\Geometry.cpp" />
|
||||
<ClCompile Include="..\..\src\kiwano\render\GeometrySink.cpp" />
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
<Filter Include="render">
|
||||
<UniqueIdentifier>{adb44ca9-674a-4b77-993f-d65193d8ab06}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="render\dx">
|
||||
<Filter Include="render\DirectX">
|
||||
<UniqueIdentifier>{fd281702-0006-46d2-8fd1-28c502464164}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
|
|
@ -222,27 +222,6 @@
|
|||
<ClInclude Include="..\..\src\kiwano\core\Time.h">
|
||||
<Filter>core</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\render\dx\D2DDeviceResources.h">
|
||||
<Filter>render\dx</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\render\dx\D3D10DeviceResources.h">
|
||||
<Filter>render\dx</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\render\dx\D3D11DeviceResources.h">
|
||||
<Filter>render\dx</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\render\dx\D3DDeviceResourcesBase.h">
|
||||
<Filter>render\dx</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\render\dx\FontCollectionLoader.h">
|
||||
<Filter>render\dx</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\render\dx\helper.h">
|
||||
<Filter>render\dx</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\render\dx\TextRenderer.h">
|
||||
<Filter>render\dx</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\render\Brush.h">
|
||||
<Filter>render</Filter>
|
||||
</ClInclude>
|
||||
|
|
@ -285,6 +264,27 @@
|
|||
<ClInclude Include="..\..\src\kiwano\render\TextureCache.h">
|
||||
<Filter>render</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\D2DDeviceResources.h">
|
||||
<Filter>render\DirectX</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\D3D10DeviceResources.h">
|
||||
<Filter>render\DirectX</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\D3D11DeviceResources.h">
|
||||
<Filter>render\DirectX</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\D3DDeviceResourcesBase.h">
|
||||
<Filter>render\DirectX</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\FontCollectionLoader.h">
|
||||
<Filter>render\DirectX</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\helper.h">
|
||||
<Filter>render\DirectX</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\kiwano\render\DirectX\TextRenderer.h">
|
||||
<Filter>render\DirectX</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\kiwano\2d\Canvas.cpp">
|
||||
|
|
@ -431,21 +431,6 @@
|
|||
<ClCompile Include="..\..\src\kiwano\core\Time.cpp">
|
||||
<Filter>core</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\render\dx\D2DDeviceResources.cpp">
|
||||
<Filter>render\dx</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\render\dx\D3D10DeviceResources.cpp">
|
||||
<Filter>render\dx</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\render\dx\D3D11DeviceResources.cpp">
|
||||
<Filter>render\dx</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\render\dx\FontCollectionLoader.cpp">
|
||||
<Filter>render\dx</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\render\dx\TextRenderer.cpp">
|
||||
<Filter>render\dx</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\render\Brush.cpp">
|
||||
<Filter>render</Filter>
|
||||
</ClCompile>
|
||||
|
|
@ -485,5 +470,20 @@
|
|||
<ClCompile Include="..\..\src\kiwano\render\TextureCache.cpp">
|
||||
<Filter>render</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\render\DirectX\D2DDeviceResources.cpp">
|
||||
<Filter>render\DirectX</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\render\DirectX\D3D10DeviceResources.cpp">
|
||||
<Filter>render\DirectX</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\render\DirectX\D3D11DeviceResources.cpp">
|
||||
<Filter>render\DirectX</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\render\DirectX\FontCollectionLoader.cpp">
|
||||
<Filter>render\DirectX</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\kiwano\render\DirectX\TextRenderer.cpp">
|
||||
<Filter>render\DirectX</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# clang-format-all: a tool to run clang-format on an entire project
|
||||
# Copyright (C) 2016 Evan Klitzke <evan@eklitzke.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
function usage {
|
||||
echo "Usage: $0 DIR..."
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
# Variable that will hold the name of the clang-format command
|
||||
FMT=""
|
||||
|
||||
# Some distros just call it clang-format. Others (e.g. Ubuntu) are insistent
|
||||
# that the version number be part of the command. We prefer clang-format if
|
||||
# that's present, otherwise we work backwards from highest version to lowest
|
||||
# version.
|
||||
for clangfmt in clang-format{,-{4,3}.{9,8,7,6,5,4,3,2,1,0}}; do
|
||||
if which "$clangfmt" &>/dev/null; then
|
||||
FMT="$clangfmt"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Check if we found a working clang-format
|
||||
if [ -z "$FMT" ]; then
|
||||
echo "failed to find clang-format"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check all of the arguments first to make sure they're all directories
|
||||
for dir in "$@"; do
|
||||
if [ ! -d "${dir}" ]; then
|
||||
echo "${dir} is not a directory"
|
||||
usage
|
||||
fi
|
||||
done
|
||||
|
||||
# Find a dominating file, starting from a given directory and going up.
|
||||
find-dominating-file() {
|
||||
if [ -r "$1"/"$2" ]; then
|
||||
return 0
|
||||
fi
|
||||
if [ "$1" = "/" ]; then
|
||||
return 1
|
||||
fi
|
||||
find-dominating-file "$(realpath "$1"/..)" "$2"
|
||||
return $?
|
||||
}
|
||||
|
||||
# Run clang-format -i on all of the things
|
||||
for dir in "$@"; do
|
||||
pushd "${dir}" &>/dev/null
|
||||
if ! find-dominating-file . .clang-format; then
|
||||
echo "Failed to find dominating .clang-format starting at $PWD"
|
||||
continue
|
||||
fi
|
||||
find . \
|
||||
\( -name '*.c' \
|
||||
-o -name '*.cc' \
|
||||
-o -name '*.cpp' \
|
||||
-o -name '*.h' \
|
||||
-o -name '*.hh' \
|
||||
-o -name '*.hpp' \) \
|
||||
-exec "${FMT}" -i '{}' \;
|
||||
popd &>/dev/null
|
||||
done
|
||||
|
|
@ -18,10 +18,10 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#include <kiwano/platform/win32/helper.h> // win32::ThrowIfFailed
|
||||
#include <kiwano/core/Logger.h>
|
||||
#include <kiwano-audio/libraries.h>
|
||||
#include <kiwano-audio/AudioEngine.h>
|
||||
#include <kiwano-audio/libraries.h>
|
||||
#include <kiwano/core/Logger.h>
|
||||
#include <kiwano/platform/win32/helper.h> // win32::ThrowIfFailed
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -33,9 +33,7 @@ namespace kiwano
|
|||
{
|
||||
}
|
||||
|
||||
AudioEngine::~AudioEngine()
|
||||
{
|
||||
}
|
||||
AudioEngine::~AudioEngine() {}
|
||||
|
||||
void AudioEngine::SetupComponent()
|
||||
{
|
||||
|
|
@ -121,5 +119,5 @@ namespace kiwano
|
|||
if (x_audio2_)
|
||||
x_audio2_->StopEngine();
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace audio
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -19,16 +19,17 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano-audio/Sound.h>
|
||||
#include <kiwano-audio/Transcoder.h>
|
||||
#include <kiwano/core/Common.h>
|
||||
#include <kiwano/core/Component.h>
|
||||
#include <kiwano-audio/Transcoder.h>
|
||||
#include <kiwano-audio/Sound.h>
|
||||
#include <xaudio2.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
namespace audio
|
||||
{
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* \defgroup Audio ÒôƵÒýÇæ
|
||||
|
|
@ -78,5 +79,6 @@ namespace kiwano
|
|||
};
|
||||
|
||||
/** @} */
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace audio
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -18,10 +18,10 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#include <kiwano-audio/AudioEngine.h>
|
||||
#include <kiwano-audio/Sound.h>
|
||||
#include <kiwano/core/Logger.h>
|
||||
#include <kiwano/platform/FileSystem.h>
|
||||
#include <kiwano-audio/Sound.h>
|
||||
#include <kiwano-audio/AudioEngine.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -223,5 +223,5 @@ namespace kiwano
|
|||
volume = std::min(std::max(volume, -224.f), 224.f);
|
||||
voice_->SetVolume(volume);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace audio
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano-audio/Transcoder.h>
|
||||
#include <kiwano/core/ObjectBase.h>
|
||||
#include <kiwano/core/Resource.h>
|
||||
#include <kiwano/platform/win32/ComPtr.hpp>
|
||||
#include <kiwano-audio/Transcoder.h>
|
||||
#include <xaudio2.h>
|
||||
|
||||
namespace kiwano
|
||||
|
|
@ -42,8 +42,7 @@ namespace kiwano
|
|||
* \~chinese
|
||||
* @brief 񙮵
|
||||
*/
|
||||
class KGE_API Sound
|
||||
: public virtual ObjectBase
|
||||
class KGE_API Sound : public virtual ObjectBase
|
||||
{
|
||||
friend class AudioEngine;
|
||||
|
||||
|
|
@ -114,7 +113,6 @@ namespace kiwano
|
|||
|
||||
/** @} */
|
||||
|
||||
|
||||
inline IXAudio2SourceVoice* Sound::GetXAudio2Voice() const
|
||||
{
|
||||
return voice_;
|
||||
|
|
@ -124,5 +122,5 @@ namespace kiwano
|
|||
{
|
||||
voice_ = voice;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace audio
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -152,5 +152,5 @@ namespace kiwano
|
|||
{
|
||||
sound_cache_.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace audio
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano/core/ObjectBase.h>
|
||||
#include <kiwano-audio/Sound.h>
|
||||
#include <kiwano/core/ObjectBase.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -37,8 +37,7 @@ namespace kiwano
|
|||
* \~chinese
|
||||
* @brief 音频播放器
|
||||
*/
|
||||
class KGE_API SoundPlayer
|
||||
: public virtual ObjectBase
|
||||
class KGE_API SoundPlayer : public virtual ObjectBase
|
||||
{
|
||||
public:
|
||||
SoundPlayer();
|
||||
|
|
@ -116,5 +115,5 @@ namespace kiwano
|
|||
};
|
||||
|
||||
/** @} */
|
||||
}
|
||||
}
|
||||
} // namespace audio
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -22,14 +22,14 @@
|
|||
#define INITGUID // MFAudioFormat_PCM, MF_MT_MAJOR_TYPE, MF_MT_SUBTYPE, MFMediaType_Audio
|
||||
#endif
|
||||
|
||||
#include <kiwano/macros.h>
|
||||
#include <kiwano-audio/Transcoder.h>
|
||||
#include <kiwano-audio/libraries.h>
|
||||
#include <kiwano/core/Common.h>
|
||||
#include <kiwano/core/Resource.h>
|
||||
#include <kiwano/core/Logger.h>
|
||||
#include <kiwano/core/Resource.h>
|
||||
#include <kiwano/macros.h>
|
||||
#include <kiwano/platform/win32/ComPtr.hpp>
|
||||
#include <kiwano/platform/win32/libraries.h>
|
||||
#include <kiwano-audio/libraries.h>
|
||||
#include <kiwano-audio/Transcoder.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -76,11 +76,7 @@ namespace kiwano
|
|||
|
||||
ComPtr<IMFSourceReader> reader;
|
||||
|
||||
hr = dlls::MediaFoundation::Get().MFCreateSourceReaderFromURL(
|
||||
file_path.c_str(),
|
||||
nullptr,
|
||||
&reader
|
||||
);
|
||||
hr = dlls::MediaFoundation::Get().MFCreateSourceReaderFromURL(file_path.c_str(), nullptr, &reader);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
|
|
@ -99,12 +95,13 @@ namespace kiwano
|
|||
ComPtr<IMFSourceReader> reader;
|
||||
|
||||
Resource::Data data = res.GetData();
|
||||
if (!data) { return E_FAIL; }
|
||||
if (!data)
|
||||
{
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
stream = win32::dlls::Shlwapi::Get().SHCreateMemStream(
|
||||
static_cast<const BYTE*>(data.buffer),
|
||||
static_cast<uint32_t>(data.size)
|
||||
);
|
||||
stream = win32::dlls::Shlwapi::Get().SHCreateMemStream(static_cast<const BYTE*>(data.buffer),
|
||||
static_cast<uint32_t>(data.size));
|
||||
|
||||
if (stream == nullptr)
|
||||
{
|
||||
|
|
@ -119,11 +116,7 @@ namespace kiwano
|
|||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = dlls::MediaFoundation::Get().MFCreateSourceReaderFromByteStream(
|
||||
byte_stream.get(),
|
||||
nullptr,
|
||||
&reader
|
||||
);
|
||||
hr = dlls::MediaFoundation::Get().MFCreateSourceReaderFromByteStream(byte_stream.get(), nullptr, &reader);
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
|
|
@ -157,29 +150,19 @@ namespace kiwano
|
|||
// 设置 source reader 的媒体类型,它将使用合适的解码器去解码这个音频
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = reader->SetCurrentMediaType(
|
||||
(DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM,
|
||||
0,
|
||||
partial_type.get()
|
||||
);
|
||||
hr = reader->SetCurrentMediaType((DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM, 0, partial_type.get());
|
||||
}
|
||||
|
||||
// 从 IMFMediaType 中获取 WAVEFORMAT 结构
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = reader->GetCurrentMediaType(
|
||||
(DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM,
|
||||
&uncompressed_type
|
||||
);
|
||||
hr = reader->GetCurrentMediaType((DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM, &uncompressed_type);
|
||||
}
|
||||
|
||||
// 指定音频流
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = reader->SetStreamSelection(
|
||||
(DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM,
|
||||
true
|
||||
);
|
||||
hr = reader->SetStreamSelection((DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM, true);
|
||||
}
|
||||
|
||||
// 获取 WAVEFORMAT 数据
|
||||
|
|
@ -187,11 +170,7 @@ namespace kiwano
|
|||
{
|
||||
uint32_t size = 0;
|
||||
hr = dlls::MediaFoundation::Get().MFCreateWaveFormatExFromMFMediaType(
|
||||
uncompressed_type.get(),
|
||||
&wave_format_,
|
||||
&size,
|
||||
(DWORD)MFWaveFormatExConvertFlag_Normal
|
||||
);
|
||||
uncompressed_type.get(), &wave_format_, &size, (DWORD)MFWaveFormatExConvertFlag_Normal);
|
||||
}
|
||||
|
||||
// 估算音频流大小
|
||||
|
|
@ -200,16 +179,10 @@ namespace kiwano
|
|||
PROPVARIANT prop;
|
||||
PropVariantInit(&prop);
|
||||
|
||||
hr = reader->GetPresentationAttribute(
|
||||
(DWORD)MF_SOURCE_READER_MEDIASOURCE,
|
||||
MF_PD_DURATION,
|
||||
&prop
|
||||
);
|
||||
hr = reader->GetPresentationAttribute((DWORD)MF_SOURCE_READER_MEDIASOURCE, MF_PD_DURATION, &prop);
|
||||
|
||||
LONGLONG duration = prop.uhVal.QuadPart;
|
||||
max_stream_size = static_cast<DWORD>(
|
||||
(duration * wave_format_->nAvgBytesPerSec) / 10000000 + 1
|
||||
);
|
||||
max_stream_size = static_cast<DWORD>((duration * wave_format_->nAvgBytesPerSec) / 10000000 + 1);
|
||||
PropVariantClear(&prop);
|
||||
}
|
||||
|
||||
|
|
@ -232,18 +205,18 @@ namespace kiwano
|
|||
{
|
||||
while (true)
|
||||
{
|
||||
hr = reader->ReadSample(
|
||||
(DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM,
|
||||
0,
|
||||
nullptr,
|
||||
&flags,
|
||||
nullptr,
|
||||
&sample
|
||||
);
|
||||
hr = reader->ReadSample((DWORD)MF_SOURCE_READER_FIRST_AUDIO_STREAM, 0, nullptr, &flags, nullptr,
|
||||
&sample);
|
||||
|
||||
if (flags & MF_SOURCE_READERF_ENDOFSTREAM) { break; }
|
||||
if (flags & MF_SOURCE_READERF_ENDOFSTREAM)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (sample == nullptr) { continue; }
|
||||
if (sample == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
|
|
@ -254,11 +227,7 @@ namespace kiwano
|
|||
BYTE* audio_data = nullptr;
|
||||
DWORD sample_buffer_length = 0;
|
||||
|
||||
hr = buffer->Lock(
|
||||
&audio_data,
|
||||
nullptr,
|
||||
&sample_buffer_length
|
||||
);
|
||||
hr = buffer->Lock(&audio_data, nullptr, &sample_buffer_length);
|
||||
|
||||
if (position + sample_buffer_length >= max_stream_size)
|
||||
{
|
||||
|
|
@ -276,7 +245,10 @@ namespace kiwano
|
|||
}
|
||||
sample = nullptr;
|
||||
|
||||
if (FAILED(hr)) { break; }
|
||||
if (FAILED(hr))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
|
|
@ -294,5 +266,5 @@ namespace kiwano
|
|||
|
||||
return hr;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace audio
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -87,5 +87,5 @@ namespace kiwano
|
|||
};
|
||||
|
||||
/** @} */
|
||||
}
|
||||
}
|
||||
} // namespace audio
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#include <kiwano/core/Logger.h>
|
||||
#include <kiwano-audio/libraries.h>
|
||||
#include <kiwano/core/Logger.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -31,8 +31,7 @@ namespace kiwano
|
|||
: xaudio2()
|
||||
, XAudio2Create(nullptr)
|
||||
{
|
||||
const auto xaudio2_dll_names =
|
||||
{
|
||||
const auto xaudio2_dll_names = {
|
||||
"xaudio2_9.dll", // for Windows 10
|
||||
"xaudio2_8.dll", // for Windows 8
|
||||
"xaudio2_7.dll" // for DirectX SDK
|
||||
|
|
@ -73,8 +72,10 @@ namespace kiwano
|
|||
MFStartup = mfplat.GetProcess<PFN_MFStartup>("MFStartup");
|
||||
MFShutdown = mfplat.GetProcess<PFN_MFShutdown>("MFShutdown");
|
||||
MFCreateMediaType = mfplat.GetProcess<PFN_MFCreateMediaType>("MFCreateMediaType");
|
||||
MFCreateWaveFormatExFromMFMediaType = mfplat.GetProcess<PFN_MFCreateWaveFormatExFromMFMediaType>("MFCreateWaveFormatExFromMFMediaType");
|
||||
MFCreateMFByteStreamOnStream = mfplat.GetProcess<PFN_MFCreateMFByteStreamOnStream>("MFCreateMFByteStreamOnStream");
|
||||
MFCreateWaveFormatExFromMFMediaType =
|
||||
mfplat.GetProcess<PFN_MFCreateWaveFormatExFromMFMediaType>("MFCreateWaveFormatExFromMFMediaType");
|
||||
MFCreateMFByteStreamOnStream =
|
||||
mfplat.GetProcess<PFN_MFCreateMFByteStreamOnStream>("MFCreateMFByteStreamOnStream");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -84,8 +85,10 @@ namespace kiwano
|
|||
|
||||
if (mfreadwrite.Load("Mfreadwrite.dll"))
|
||||
{
|
||||
MFCreateSourceReaderFromURL = mfreadwrite.GetProcess<PFN_MFCreateSourceReaderFromURL>("MFCreateSourceReaderFromURL");
|
||||
MFCreateSourceReaderFromByteStream = mfreadwrite.GetProcess<PFN_MFCreateSourceReaderFromByteStream>("MFCreateSourceReaderFromByteStream");
|
||||
MFCreateSourceReaderFromURL =
|
||||
mfreadwrite.GetProcess<PFN_MFCreateSourceReaderFromURL>("MFCreateSourceReaderFromURL");
|
||||
MFCreateSourceReaderFromByteStream =
|
||||
mfreadwrite.GetProcess<PFN_MFCreateSourceReaderFromByteStream>("MFCreateSourceReaderFromByteStream");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -93,6 +96,6 @@ namespace kiwano
|
|||
throw std::runtime_error("Load Mfreadwrite.dll failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace dlls
|
||||
} // namespace audio
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@
|
|||
|
||||
#pragma once
|
||||
#include <kiwano/core/Library.h>
|
||||
#include <xaudio2.h>
|
||||
#include <mfapi.h>
|
||||
#include <mfidl.h>
|
||||
#include <mfreadwrite.h>
|
||||
#include <xaudio2.h>
|
||||
|
||||
#ifndef KGE_DOXYGEN_DO_NOT_INCLUDE
|
||||
|
||||
|
|
@ -56,7 +56,6 @@ namespace kiwano
|
|||
Library xaudio2;
|
||||
};
|
||||
|
||||
|
||||
class KGE_API MediaFoundation
|
||||
{
|
||||
public:
|
||||
|
|
@ -92,8 +91,8 @@ namespace kiwano
|
|||
Library mfplat;
|
||||
Library mfreadwrite;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace dlls
|
||||
} // namespace audio
|
||||
} // namespace kiwano
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -29,9 +29,7 @@ namespace kiwano
|
|||
SetSwallowEvents(true);
|
||||
}
|
||||
|
||||
ImGuiLayer::~ImGuiLayer()
|
||||
{
|
||||
}
|
||||
ImGuiLayer::~ImGuiLayer() {}
|
||||
|
||||
void ImGuiLayer::OnRender(RenderContext& ctx)
|
||||
{
|
||||
|
|
@ -64,5 +62,5 @@ namespace kiwano
|
|||
{
|
||||
pipelines_.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace imgui
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -35,8 +35,7 @@ namespace kiwano
|
|||
* \~chinese
|
||||
* @brief ImGuiͼ²ã
|
||||
*/
|
||||
class ImGuiLayer
|
||||
: public Layer
|
||||
class ImGuiLayer : public Layer
|
||||
{
|
||||
public:
|
||||
ImGuiLayer();
|
||||
|
|
@ -67,5 +66,5 @@ namespace kiwano
|
|||
private:
|
||||
Map<String, ImGuiPipeline> pipelines_;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace imgui
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
// Copyright (C) 2019 Nomango
|
||||
|
||||
#include <kiwano-imgui/ImGuiModule.h>
|
||||
#include <kiwano-imgui/imgui_impl.h>
|
||||
#include <kiwano/core/Common.h>
|
||||
#include <kiwano/core/event/KeyEvent.h>
|
||||
#include <kiwano/core/event/MouseEvent.h>
|
||||
#include <kiwano/platform/Window.h>
|
||||
#include <kiwano/platform/Input.h>
|
||||
#include <kiwano/platform/Window.h>
|
||||
#include <kiwano/render/Renderer.h>
|
||||
#include <kiwano-imgui/ImGuiModule.h>
|
||||
#include <kiwano-imgui/imgui_impl.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -23,7 +23,8 @@ namespace kiwano
|
|||
// Setup Dear ImGui context
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
(void)io;
|
||||
|
||||
// Setup Dear ImGui style
|
||||
ImGui::StyleColorsDark();
|
||||
|
|
@ -32,11 +33,13 @@ namespace kiwano
|
|||
target_window_ = Renderer::Instance().GetTargetWindow();
|
||||
|
||||
io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
|
||||
io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
|
||||
io.BackendFlags |=
|
||||
ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
|
||||
io.BackendPlatformName = "imgui_impl_win32";
|
||||
io.ImeWindowHandle = target_window_;
|
||||
|
||||
// Keyboard mapping. ImGui will use those indices to peek into the io.KeysDown[] array that we will update during the application lifetime.
|
||||
// Keyboard mapping. ImGui will use those indices to peek into the io.KeysDown[] array that we will update during
|
||||
// the application lifetime.
|
||||
io.KeyMap[ImGuiKey_Tab] = (int)KeyCode::Tab;
|
||||
io.KeyMap[ImGuiKey_LeftArrow] = (int)KeyCode::Left;
|
||||
io.KeyMap[ImGuiKey_RightArrow] = (int)KeyCode::Right;
|
||||
|
|
@ -106,18 +109,24 @@ namespace kiwano
|
|||
{
|
||||
MouseButton button = dynamic_cast<MouseDownEvent*>(evt)->button;
|
||||
int index = 0;
|
||||
if (button == MouseButton::Left) index = 0;
|
||||
else if (button == MouseButton::Right) index = 1;
|
||||
else if (button == MouseButton::Middle) index = 2;
|
||||
if (button == MouseButton::Left)
|
||||
index = 0;
|
||||
else if (button == MouseButton::Right)
|
||||
index = 1;
|
||||
else if (button == MouseButton::Middle)
|
||||
index = 2;
|
||||
io.MouseDown[index] = true;
|
||||
}
|
||||
else if (evt->IsType<MouseUpEvent>())
|
||||
{
|
||||
MouseButton button = dynamic_cast<MouseUpEvent*>(evt)->button;
|
||||
int index = 0;
|
||||
if (button == MouseButton::Left) index = 0;
|
||||
else if (button == MouseButton::Right) index = 1;
|
||||
else if (button == MouseButton::Middle) index = 2;
|
||||
if (button == MouseButton::Left)
|
||||
index = 0;
|
||||
else if (button == MouseButton::Right)
|
||||
index = 1;
|
||||
else if (button == MouseButton::Middle)
|
||||
index = 2;
|
||||
io.MouseDown[index] = false;
|
||||
}
|
||||
else if (evt->IsType<MouseWheelEvent>())
|
||||
|
|
@ -172,7 +181,8 @@ namespace kiwano
|
|||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
// Set OS mouse position if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user)
|
||||
// Set OS mouse position if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by
|
||||
// user)
|
||||
if (io.WantSetMousePos)
|
||||
{
|
||||
POINT pos = { (int)io.MousePos.x, (int)io.MousePos.y };
|
||||
|
|
@ -192,18 +202,34 @@ namespace kiwano
|
|||
CursorType cursor = CursorType::Arrow;
|
||||
switch (ImGui::GetMouseCursor())
|
||||
{
|
||||
case ImGuiMouseCursor_Arrow: cursor = CursorType::Arrow; break;
|
||||
case ImGuiMouseCursor_TextInput: cursor = CursorType::TextInput; break;
|
||||
case ImGuiMouseCursor_ResizeAll: cursor = CursorType::SizeAll; break;
|
||||
case ImGuiMouseCursor_ResizeEW: cursor = CursorType::SizeWE; break;
|
||||
case ImGuiMouseCursor_ResizeNS: cursor = CursorType::SizeNS; break;
|
||||
case ImGuiMouseCursor_ResizeNESW: cursor = CursorType::SizeNESW; break;
|
||||
case ImGuiMouseCursor_ResizeNWSE: cursor = CursorType::SizeNWSE; break;
|
||||
case ImGuiMouseCursor_Hand: cursor = CursorType::Hand; break;
|
||||
case ImGuiMouseCursor_Arrow:
|
||||
cursor = CursorType::Arrow;
|
||||
break;
|
||||
case ImGuiMouseCursor_TextInput:
|
||||
cursor = CursorType::TextInput;
|
||||
break;
|
||||
case ImGuiMouseCursor_ResizeAll:
|
||||
cursor = CursorType::SizeAll;
|
||||
break;
|
||||
case ImGuiMouseCursor_ResizeEW:
|
||||
cursor = CursorType::SizeWE;
|
||||
break;
|
||||
case ImGuiMouseCursor_ResizeNS:
|
||||
cursor = CursorType::SizeNS;
|
||||
break;
|
||||
case ImGuiMouseCursor_ResizeNESW:
|
||||
cursor = CursorType::SizeNESW;
|
||||
break;
|
||||
case ImGuiMouseCursor_ResizeNWSE:
|
||||
cursor = CursorType::SizeNWSE;
|
||||
break;
|
||||
case ImGuiMouseCursor_Hand:
|
||||
cursor = CursorType::Hand;
|
||||
break;
|
||||
}
|
||||
|
||||
Window::Instance().SetCursor(cursor);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace imgui
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -65,5 +65,5 @@ namespace kiwano
|
|||
private:
|
||||
WindowHandle target_window_;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace imgui
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -8,25 +8,62 @@
|
|||
|
||||
#include <kiwano-imgui/imgui_impl_dx11.h>
|
||||
|
||||
inline bool ImGui_Impl_Init(::kiwano::Renderer& renderer) { return ImGui_ImplDX11_Init(renderer.GetD3DDeviceResources()->GetDevice(), renderer.GetD3DDeviceResources()->GetDeviceContext()); }
|
||||
inline void ImGui_Impl_Shutdown() { ImGui_ImplDX11_Shutdown(); }
|
||||
inline void ImGui_Impl_NewFrame() { ImGui_ImplDX11_NewFrame(); }
|
||||
inline void ImGui_Impl_RenderDrawData(ImDrawData* draw_data) { ImGui_ImplDX11_RenderDrawData(draw_data); }
|
||||
inline bool ImGui_Impl_Init(::kiwano::Renderer& renderer)
|
||||
{
|
||||
return ImGui_ImplDX11_Init(renderer.GetD3DDeviceResources()->GetDevice(),
|
||||
renderer.GetD3DDeviceResources()->GetDeviceContext());
|
||||
}
|
||||
inline void ImGui_Impl_Shutdown()
|
||||
{
|
||||
ImGui_ImplDX11_Shutdown();
|
||||
}
|
||||
inline void ImGui_Impl_NewFrame()
|
||||
{
|
||||
ImGui_ImplDX11_NewFrame();
|
||||
}
|
||||
inline void ImGui_Impl_RenderDrawData(ImDrawData* draw_data)
|
||||
{
|
||||
ImGui_ImplDX11_RenderDrawData(draw_data);
|
||||
}
|
||||
|
||||
inline void ImGui_Impl_InvalidateDeviceObjects() { ImGui_ImplDX11_InvalidateDeviceObjects(); }
|
||||
inline bool ImGui_Impl_CreateDeviceObjects() { return ImGui_ImplDX11_CreateDeviceObjects(); }
|
||||
inline void ImGui_Impl_InvalidateDeviceObjects()
|
||||
{
|
||||
ImGui_ImplDX11_InvalidateDeviceObjects();
|
||||
}
|
||||
inline bool ImGui_Impl_CreateDeviceObjects()
|
||||
{
|
||||
return ImGui_ImplDX11_CreateDeviceObjects();
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <kiwano-imgui/imgui_impl_dx10.h>
|
||||
|
||||
inline bool ImGui_Impl_Init(::kiwano::Renderer& renderer) { return ImGui_ImplDX10_Init(renderer.GetD3DDeviceResources()->GetDevice()); }
|
||||
inline void ImGui_Impl_Shutdown() { ImGui_ImplDX10_Shutdown(); }
|
||||
inline void ImGui_Impl_NewFrame() { ImGui_ImplDX10_NewFrame(); }
|
||||
inline void ImGui_Impl_RenderDrawData(ImDrawData* draw_data) { ImGui_ImplDX10_RenderDrawData(draw_data); }
|
||||
inline bool ImGui_Impl_Init(::kiwano::Renderer& renderer)
|
||||
{
|
||||
return ImGui_ImplDX10_Init(renderer.GetD3DDeviceResources()->GetDevice());
|
||||
}
|
||||
inline void ImGui_Impl_Shutdown()
|
||||
{
|
||||
ImGui_ImplDX10_Shutdown();
|
||||
}
|
||||
inline void ImGui_Impl_NewFrame()
|
||||
{
|
||||
ImGui_ImplDX10_NewFrame();
|
||||
}
|
||||
inline void ImGui_Impl_RenderDrawData(ImDrawData* draw_data)
|
||||
{
|
||||
ImGui_ImplDX10_RenderDrawData(draw_data);
|
||||
}
|
||||
|
||||
inline void ImGui_Impl_InvalidateDeviceObjects() { ImGui_ImplDX10_InvalidateDeviceObjects(); }
|
||||
inline bool ImGui_Impl_CreateDeviceObjects() { return ImGui_ImplDX10_CreateDeviceObjects(); }
|
||||
inline void ImGui_Impl_InvalidateDeviceObjects()
|
||||
{
|
||||
ImGui_ImplDX10_InvalidateDeviceObjects();
|
||||
}
|
||||
inline bool ImGui_Impl_CreateDeviceObjects()
|
||||
{
|
||||
return ImGui_ImplDX10_CreateDeviceObjects();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
#include <kiwano-imgui/imgui_impl_dx10.h>
|
||||
|
||||
// DirectX
|
||||
#include <stdio.h>
|
||||
#include <d3d10_1.h>
|
||||
#include <d3d10.h>
|
||||
#include <d3d10_1.h>
|
||||
#include <d3dcompiler.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma comment(lib, "d3dcompiler") // Automatically link with d3dcompiler.lib as we are using D3DCompile() below.
|
||||
|
|
@ -36,7 +36,8 @@ struct VERTEX_CONSTANT_BUFFER
|
|||
};
|
||||
|
||||
// Render Function
|
||||
// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
|
||||
// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from
|
||||
// your main loop)
|
||||
void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
|
||||
{
|
||||
ID3D10Device* ctx = g_pd3dDevice;
|
||||
|
|
@ -44,7 +45,11 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
|
|||
// Create and grow vertex/index buffers if needed
|
||||
if (!g_pVB || g_VertexBufferSize < draw_data->TotalVtxCount)
|
||||
{
|
||||
if (g_pVB) { g_pVB->Release(); g_pVB = NULL; }
|
||||
if (g_pVB)
|
||||
{
|
||||
g_pVB->Release();
|
||||
g_pVB = NULL;
|
||||
}
|
||||
g_VertexBufferSize = draw_data->TotalVtxCount + 5000;
|
||||
D3D10_BUFFER_DESC desc;
|
||||
memset(&desc, 0, sizeof(D3D10_BUFFER_DESC));
|
||||
|
|
@ -59,7 +64,11 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
|
|||
|
||||
if (!g_pIB || g_IndexBufferSize < draw_data->TotalIdxCount)
|
||||
{
|
||||
if (g_pIB) { g_pIB->Release(); g_pIB = NULL; }
|
||||
if (g_pIB)
|
||||
{
|
||||
g_pIB->Release();
|
||||
g_pIB = NULL;
|
||||
}
|
||||
g_IndexBufferSize = draw_data->TotalIdxCount + 10000;
|
||||
D3D10_BUFFER_DESC desc;
|
||||
memset(&desc, 0, sizeof(D3D10_BUFFER_DESC));
|
||||
|
|
@ -88,7 +97,8 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
|
|||
g_pIB->Unmap();
|
||||
|
||||
// Setup orthographic projection matrix into our constant buffer
|
||||
// Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right).
|
||||
// Our visible imgui space lies from draw_data->DisplayPos (top left) to
|
||||
// draw_data->DisplayPos+data_data->DisplaySize (bottom right).
|
||||
{
|
||||
void* mapped_resource;
|
||||
if (g_pVertexConstantBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &mapped_resource) != S_OK)
|
||||
|
|
@ -98,8 +108,7 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
|
|||
float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
|
||||
float T = draw_data->DisplayPos.y;
|
||||
float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y;
|
||||
float mvp[4][4] =
|
||||
{
|
||||
float mvp[4][4] = {
|
||||
{ 2.0f / (R - L), 0.0f, 0.0f, 0.0f },
|
||||
{ 0.0f, 2.0f / (T - B), 0.0f, 0.0f },
|
||||
{ 0.0f, 0.0f, 0.5f, 0.0f },
|
||||
|
|
@ -109,7 +118,8 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
|
|||
g_pVertexConstantBuffer->Unmap();
|
||||
}
|
||||
|
||||
// Backup DX state that will be modified to restore it afterwards (unfortunately this is very ugly looking and verbose. Close your eyes!)
|
||||
// Backup DX state that will be modified to restore it afterwards (unfortunately this is very ugly looking and
|
||||
// verbose. Close your eyes!)
|
||||
struct BACKUP_DX10_STATE
|
||||
{
|
||||
UINT ScissorRectsCount, ViewportsCount;
|
||||
|
|
@ -194,7 +204,8 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
|
|||
else
|
||||
{
|
||||
// Apply scissor/clipping rectangle
|
||||
const D3D10_RECT r = { (LONG)(pcmd->ClipRect.x - pos.x), (LONG)(pcmd->ClipRect.y - pos.y), (LONG)(pcmd->ClipRect.z - pos.x), (LONG)(pcmd->ClipRect.w - pos.y)};
|
||||
const D3D10_RECT r = { (LONG)(pcmd->ClipRect.x - pos.x), (LONG)(pcmd->ClipRect.y - pos.y),
|
||||
(LONG)(pcmd->ClipRect.z - pos.x), (LONG)(pcmd->ClipRect.w - pos.y) };
|
||||
ctx->RSSetScissorRects(1, &r);
|
||||
|
||||
// Bind texture, Draw
|
||||
|
|
@ -210,18 +221,40 @@ void ImGui_ImplDX10_RenderDrawData(ImDrawData* draw_data)
|
|||
// Restore modified DX state
|
||||
ctx->RSSetScissorRects(old.ScissorRectsCount, old.ScissorRects);
|
||||
ctx->RSSetViewports(old.ViewportsCount, old.Viewports);
|
||||
ctx->RSSetState(old.RS); if (old.RS) old.RS->Release();
|
||||
ctx->OMSetBlendState(old.BlendState, old.BlendFactor, old.SampleMask); if (old.BlendState) old.BlendState->Release();
|
||||
ctx->OMSetDepthStencilState(old.DepthStencilState, old.StencilRef); if (old.DepthStencilState) old.DepthStencilState->Release();
|
||||
ctx->PSSetShaderResources(0, 1, &old.PSShaderResource); if (old.PSShaderResource) old.PSShaderResource->Release();
|
||||
ctx->PSSetSamplers(0, 1, &old.PSSampler); if (old.PSSampler) old.PSSampler->Release();
|
||||
ctx->PSSetShader(old.PS); if (old.PS) old.PS->Release();
|
||||
ctx->VSSetShader(old.VS); if (old.VS) old.VS->Release();
|
||||
ctx->VSSetConstantBuffers(0, 1, &old.VSConstantBuffer); if (old.VSConstantBuffer) old.VSConstantBuffer->Release();
|
||||
ctx->RSSetState(old.RS);
|
||||
if (old.RS)
|
||||
old.RS->Release();
|
||||
ctx->OMSetBlendState(old.BlendState, old.BlendFactor, old.SampleMask);
|
||||
if (old.BlendState)
|
||||
old.BlendState->Release();
|
||||
ctx->OMSetDepthStencilState(old.DepthStencilState, old.StencilRef);
|
||||
if (old.DepthStencilState)
|
||||
old.DepthStencilState->Release();
|
||||
ctx->PSSetShaderResources(0, 1, &old.PSShaderResource);
|
||||
if (old.PSShaderResource)
|
||||
old.PSShaderResource->Release();
|
||||
ctx->PSSetSamplers(0, 1, &old.PSSampler);
|
||||
if (old.PSSampler)
|
||||
old.PSSampler->Release();
|
||||
ctx->PSSetShader(old.PS);
|
||||
if (old.PS)
|
||||
old.PS->Release();
|
||||
ctx->VSSetShader(old.VS);
|
||||
if (old.VS)
|
||||
old.VS->Release();
|
||||
ctx->VSSetConstantBuffers(0, 1, &old.VSConstantBuffer);
|
||||
if (old.VSConstantBuffer)
|
||||
old.VSConstantBuffer->Release();
|
||||
ctx->IASetPrimitiveTopology(old.PrimitiveTopology);
|
||||
ctx->IASetIndexBuffer(old.IndexBuffer, old.IndexBufferFormat, old.IndexBufferOffset); if (old.IndexBuffer) old.IndexBuffer->Release();
|
||||
ctx->IASetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset); if (old.VertexBuffer) old.VertexBuffer->Release();
|
||||
ctx->IASetInputLayout(old.InputLayout); if (old.InputLayout) old.InputLayout->Release();
|
||||
ctx->IASetIndexBuffer(old.IndexBuffer, old.IndexBufferFormat, old.IndexBufferOffset);
|
||||
if (old.IndexBuffer)
|
||||
old.IndexBuffer->Release();
|
||||
ctx->IASetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset);
|
||||
if (old.VertexBuffer)
|
||||
old.VertexBuffer->Release();
|
||||
ctx->IASetInputLayout(old.InputLayout);
|
||||
if (old.InputLayout)
|
||||
old.InputLayout->Release();
|
||||
}
|
||||
|
||||
static void ImGui_ImplDX10_CreateFontsTexture()
|
||||
|
|
@ -290,16 +323,17 @@ bool ImGui_ImplDX10_CreateDeviceObjects()
|
|||
if (g_pFontSampler)
|
||||
ImGui_ImplDX10_InvalidateDeviceObjects();
|
||||
|
||||
// By using D3DCompile() from <d3dcompiler.h> / d3dcompiler.lib, we introduce a dependency to a given version of d3dcompiler_XX.dll (see D3DCOMPILER_DLL_A)
|
||||
// If you would like to use this DX10 sample code but remove this dependency you can:
|
||||
// 1) compile once, save the compiled shader blobs into a file or source code and pass them to CreateVertexShader()/CreatePixelShader() [preferred solution]
|
||||
// 2) use code to detect any version of the DLL and grab a pointer to D3DCompile from the DLL.
|
||||
// By using D3DCompile() from <d3dcompiler.h> / d3dcompiler.lib, we introduce a dependency to a given version of
|
||||
// d3dcompiler_XX.dll (see D3DCOMPILER_DLL_A) If you would like to use this DX10 sample code but remove this
|
||||
// dependency you can:
|
||||
// 1) compile once, save the compiled shader blobs into a file or source code and pass them to
|
||||
// CreateVertexShader()/CreatePixelShader() [preferred solution] 2) use code to detect any version of the DLL and
|
||||
// grab a pointer to D3DCompile from the DLL.
|
||||
// See https://github.com/ocornut/imgui/pull/638 for sources and details.
|
||||
|
||||
// Create the vertex shader
|
||||
{
|
||||
static const char* vertexShader =
|
||||
"cbuffer vertexBuffer : register(b0) \
|
||||
static const char* vertexShader = "cbuffer vertexBuffer : register(b0) \
|
||||
{\
|
||||
float4x4 ProjectionMatrix; \
|
||||
};\
|
||||
|
|
@ -326,20 +360,29 @@ bool ImGui_ImplDX10_CreateDeviceObjects()
|
|||
return output;\
|
||||
}";
|
||||
|
||||
D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_4_0", 0, 0, &g_pVertexShaderBlob, NULL);
|
||||
if (g_pVertexShaderBlob == NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
|
||||
D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_4_0", 0, 0, &g_pVertexShaderBlob,
|
||||
NULL);
|
||||
if (g_pVertexShaderBlob
|
||||
== NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const
|
||||
// char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
|
||||
return false;
|
||||
if (g_pd3dDevice->CreateVertexShader((DWORD*)g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), &g_pVertexShader) != S_OK)
|
||||
if (g_pd3dDevice->CreateVertexShader((DWORD*)g_pVertexShaderBlob->GetBufferPointer(),
|
||||
g_pVertexShaderBlob->GetBufferSize(), &g_pVertexShader)
|
||||
!= S_OK)
|
||||
return false;
|
||||
|
||||
// Create the input layout
|
||||
D3D10_INPUT_ELEMENT_DESC local_layout[] =
|
||||
{
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->pos), D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->uv), D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (size_t)(&((ImDrawVert*)0)->col), D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
||||
D3D10_INPUT_ELEMENT_DESC local_layout[] = {
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->pos), D3D10_INPUT_PER_VERTEX_DATA,
|
||||
0 },
|
||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->uv), D3D10_INPUT_PER_VERTEX_DATA,
|
||||
0 },
|
||||
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (size_t)(&((ImDrawVert*)0)->col), D3D10_INPUT_PER_VERTEX_DATA,
|
||||
0 },
|
||||
};
|
||||
if (g_pd3dDevice->CreateInputLayout(local_layout, 3, g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), &g_pInputLayout) != S_OK)
|
||||
if (g_pd3dDevice->CreateInputLayout(local_layout, 3, g_pVertexShaderBlob->GetBufferPointer(),
|
||||
g_pVertexShaderBlob->GetBufferSize(), &g_pInputLayout)
|
||||
!= S_OK)
|
||||
return false;
|
||||
|
||||
// Create the constant buffer
|
||||
|
|
@ -356,8 +399,7 @@ bool ImGui_ImplDX10_CreateDeviceObjects()
|
|||
|
||||
// Create the pixel shader
|
||||
{
|
||||
static const char* pixelShader =
|
||||
"struct PS_INPUT\
|
||||
static const char* pixelShader = "struct PS_INPUT\
|
||||
{\
|
||||
float4 pos : SV_POSITION;\
|
||||
float4 col : COLOR0;\
|
||||
|
|
@ -372,10 +414,15 @@ bool ImGui_ImplDX10_CreateDeviceObjects()
|
|||
return out_col; \
|
||||
}";
|
||||
|
||||
D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_4_0", 0, 0, &g_pPixelShaderBlob, NULL);
|
||||
if (g_pPixelShaderBlob == NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
|
||||
D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_4_0", 0, 0, &g_pPixelShaderBlob,
|
||||
NULL);
|
||||
if (g_pPixelShaderBlob
|
||||
== NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const
|
||||
// char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
|
||||
return false;
|
||||
if (g_pd3dDevice->CreatePixelShader((DWORD*)g_pPixelShaderBlob->GetBufferPointer(), g_pPixelShaderBlob->GetBufferSize(), &g_pPixelShader) != S_OK)
|
||||
if (g_pd3dDevice->CreatePixelShader((DWORD*)g_pPixelShaderBlob->GetBufferPointer(),
|
||||
g_pPixelShaderBlob->GetBufferSize(), &g_pPixelShader)
|
||||
!= S_OK)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -414,7 +461,8 @@ bool ImGui_ImplDX10_CreateDeviceObjects()
|
|||
desc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL;
|
||||
desc.DepthFunc = D3D10_COMPARISON_ALWAYS;
|
||||
desc.StencilEnable = false;
|
||||
desc.FrontFace.StencilFailOp = desc.FrontFace.StencilDepthFailOp = desc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP;
|
||||
desc.FrontFace.StencilFailOp = desc.FrontFace.StencilDepthFailOp = desc.FrontFace.StencilPassOp =
|
||||
D3D10_STENCIL_OP_KEEP;
|
||||
desc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS;
|
||||
desc.BackFace = desc.FrontFace;
|
||||
g_pd3dDevice->CreateDepthStencilState(&desc, &g_pDepthStencilState);
|
||||
|
|
@ -430,20 +478,73 @@ void ImGui_ImplDX10_InvalidateDeviceObjects()
|
|||
if (!g_pd3dDevice)
|
||||
return;
|
||||
|
||||
if (g_pFontSampler) { g_pFontSampler->Release(); g_pFontSampler = NULL; }
|
||||
if (g_pFontTextureView) { g_pFontTextureView->Release(); g_pFontTextureView = NULL; ImGui::GetIO().Fonts->TexID = NULL; } // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well.
|
||||
if (g_pIB) { g_pIB->Release(); g_pIB = NULL; }
|
||||
if (g_pVB) { g_pVB->Release(); g_pVB = NULL; }
|
||||
if (g_pFontSampler)
|
||||
{
|
||||
g_pFontSampler->Release();
|
||||
g_pFontSampler = NULL;
|
||||
}
|
||||
if (g_pFontTextureView)
|
||||
{
|
||||
g_pFontTextureView->Release();
|
||||
g_pFontTextureView = NULL;
|
||||
ImGui::GetIO().Fonts->TexID = NULL;
|
||||
} // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well.
|
||||
if (g_pIB)
|
||||
{
|
||||
g_pIB->Release();
|
||||
g_pIB = NULL;
|
||||
}
|
||||
if (g_pVB)
|
||||
{
|
||||
g_pVB->Release();
|
||||
g_pVB = NULL;
|
||||
}
|
||||
|
||||
if (g_pBlendState) { g_pBlendState->Release(); g_pBlendState = NULL; }
|
||||
if (g_pDepthStencilState) { g_pDepthStencilState->Release(); g_pDepthStencilState = NULL; }
|
||||
if (g_pRasterizerState) { g_pRasterizerState->Release(); g_pRasterizerState = NULL; }
|
||||
if (g_pPixelShader) { g_pPixelShader->Release(); g_pPixelShader = NULL; }
|
||||
if (g_pPixelShaderBlob) { g_pPixelShaderBlob->Release(); g_pPixelShaderBlob = NULL; }
|
||||
if (g_pVertexConstantBuffer) { g_pVertexConstantBuffer->Release(); g_pVertexConstantBuffer = NULL; }
|
||||
if (g_pInputLayout) { g_pInputLayout->Release(); g_pInputLayout = NULL; }
|
||||
if (g_pVertexShader) { g_pVertexShader->Release(); g_pVertexShader = NULL; }
|
||||
if (g_pVertexShaderBlob) { g_pVertexShaderBlob->Release(); g_pVertexShaderBlob = NULL; }
|
||||
if (g_pBlendState)
|
||||
{
|
||||
g_pBlendState->Release();
|
||||
g_pBlendState = NULL;
|
||||
}
|
||||
if (g_pDepthStencilState)
|
||||
{
|
||||
g_pDepthStencilState->Release();
|
||||
g_pDepthStencilState = NULL;
|
||||
}
|
||||
if (g_pRasterizerState)
|
||||
{
|
||||
g_pRasterizerState->Release();
|
||||
g_pRasterizerState = NULL;
|
||||
}
|
||||
if (g_pPixelShader)
|
||||
{
|
||||
g_pPixelShader->Release();
|
||||
g_pPixelShader = NULL;
|
||||
}
|
||||
if (g_pPixelShaderBlob)
|
||||
{
|
||||
g_pPixelShaderBlob->Release();
|
||||
g_pPixelShaderBlob = NULL;
|
||||
}
|
||||
if (g_pVertexConstantBuffer)
|
||||
{
|
||||
g_pVertexConstantBuffer->Release();
|
||||
g_pVertexConstantBuffer = NULL;
|
||||
}
|
||||
if (g_pInputLayout)
|
||||
{
|
||||
g_pInputLayout->Release();
|
||||
g_pInputLayout = NULL;
|
||||
}
|
||||
if (g_pVertexShader)
|
||||
{
|
||||
g_pVertexShader->Release();
|
||||
g_pVertexShader = NULL;
|
||||
}
|
||||
if (g_pVertexShaderBlob)
|
||||
{
|
||||
g_pVertexShaderBlob->Release();
|
||||
g_pVertexShaderBlob = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool ImGui_ImplDX10_Init(ID3D10Device* device)
|
||||
|
|
@ -463,8 +564,10 @@ bool ImGui_ImplDX10_Init(ID3D10Device* device)
|
|||
g_pd3dDevice = device;
|
||||
g_pFactory = pFactory;
|
||||
}
|
||||
if (pDXGIDevice) pDXGIDevice->Release();
|
||||
if (pDXGIAdapter) pDXGIAdapter->Release();
|
||||
if (pDXGIDevice)
|
||||
pDXGIDevice->Release();
|
||||
if (pDXGIAdapter)
|
||||
pDXGIAdapter->Release();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -472,7 +575,11 @@ bool ImGui_ImplDX10_Init(ID3D10Device* device)
|
|||
void ImGui_ImplDX10_Shutdown()
|
||||
{
|
||||
ImGui_ImplDX10_InvalidateDeviceObjects();
|
||||
if (g_pFactory) { g_pFactory->Release(); g_pFactory = NULL; }
|
||||
if (g_pFactory)
|
||||
{
|
||||
g_pFactory->Release();
|
||||
g_pFactory = NULL;
|
||||
}
|
||||
g_pd3dDevice = NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@
|
|||
#include <kiwano-imgui/imgui_impl_dx11.h>
|
||||
|
||||
// DirectX
|
||||
#include <stdio.h>
|
||||
#include <d3d11.h>
|
||||
#include <d3dcompiler.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma comment(lib, "d3dcompiler") // Automatically link with d3dcompiler.lib as we are using D3DCompile() below.
|
||||
|
|
@ -36,7 +36,8 @@ struct VERTEX_CONSTANT_BUFFER
|
|||
};
|
||||
|
||||
// Render Function
|
||||
// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
|
||||
// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from
|
||||
// your main loop)
|
||||
void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
|
||||
{
|
||||
ID3D11DeviceContext* ctx = g_pd3dDeviceContext;
|
||||
|
|
@ -44,7 +45,11 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
|
|||
// Create and grow vertex/index buffers if needed
|
||||
if (!g_pVB || g_VertexBufferSize < draw_data->TotalVtxCount)
|
||||
{
|
||||
if (g_pVB) { g_pVB->Release(); g_pVB = NULL; }
|
||||
if (g_pVB)
|
||||
{
|
||||
g_pVB->Release();
|
||||
g_pVB = NULL;
|
||||
}
|
||||
g_VertexBufferSize = draw_data->TotalVtxCount + 5000;
|
||||
D3D11_BUFFER_DESC desc;
|
||||
memset(&desc, 0, sizeof(D3D11_BUFFER_DESC));
|
||||
|
|
@ -58,7 +63,11 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
|
|||
}
|
||||
if (!g_pIB || g_IndexBufferSize < draw_data->TotalIdxCount)
|
||||
{
|
||||
if (g_pIB) { g_pIB->Release(); g_pIB = NULL; }
|
||||
if (g_pIB)
|
||||
{
|
||||
g_pIB->Release();
|
||||
g_pIB = NULL;
|
||||
}
|
||||
g_IndexBufferSize = draw_data->TotalIdxCount + 10000;
|
||||
D3D11_BUFFER_DESC desc;
|
||||
memset(&desc, 0, sizeof(D3D11_BUFFER_DESC));
|
||||
|
|
@ -90,7 +99,8 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
|
|||
ctx->Unmap(g_pIB, 0);
|
||||
|
||||
// Setup orthographic projection matrix into our constant buffer
|
||||
// Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right).
|
||||
// Our visible imgui space lies from draw_data->DisplayPos (top left) to
|
||||
// draw_data->DisplayPos+data_data->DisplaySize (bottom right).
|
||||
{
|
||||
D3D11_MAPPED_SUBRESOURCE mapped_resource;
|
||||
if (ctx->Map(g_pVertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_resource) != S_OK)
|
||||
|
|
@ -100,8 +110,7 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
|
|||
float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
|
||||
float T = draw_data->DisplayPos.y;
|
||||
float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y;
|
||||
float mvp[4][4] =
|
||||
{
|
||||
float mvp[4][4] = {
|
||||
{ 2.0f / (R - L), 0.0f, 0.0f, 0.0f },
|
||||
{ 0.0f, 2.0f / (T - B), 0.0f, 0.0f },
|
||||
{ 0.0f, 0.0f, 0.5f, 0.0f },
|
||||
|
|
@ -111,7 +120,8 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
|
|||
ctx->Unmap(g_pVertexConstantBuffer, 0);
|
||||
}
|
||||
|
||||
// Backup DX state that will be modified to restore it afterwards (unfortunately this is very ugly looking and verbose. Close your eyes!)
|
||||
// Backup DX state that will be modified to restore it afterwards (unfortunately this is very ugly looking and
|
||||
// verbose. Close your eyes!)
|
||||
struct BACKUP_DX11_STATE
|
||||
{
|
||||
UINT ScissorRectsCount, ViewportsCount;
|
||||
|
|
@ -199,7 +209,8 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
|
|||
else
|
||||
{
|
||||
// Apply scissor/clipping rectangle
|
||||
const D3D11_RECT r = { (LONG)(pcmd->ClipRect.x - pos.x), (LONG)(pcmd->ClipRect.y - pos.y), (LONG)(pcmd->ClipRect.z - pos.x), (LONG)(pcmd->ClipRect.w - pos.y) };
|
||||
const D3D11_RECT r = { (LONG)(pcmd->ClipRect.x - pos.x), (LONG)(pcmd->ClipRect.y - pos.y),
|
||||
(LONG)(pcmd->ClipRect.z - pos.x), (LONG)(pcmd->ClipRect.w - pos.y) };
|
||||
ctx->RSSetScissorRects(1, &r);
|
||||
|
||||
// Bind texture, Draw
|
||||
|
|
@ -215,20 +226,46 @@ void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data)
|
|||
// Restore modified DX state
|
||||
ctx->RSSetScissorRects(old.ScissorRectsCount, old.ScissorRects);
|
||||
ctx->RSSetViewports(old.ViewportsCount, old.Viewports);
|
||||
ctx->RSSetState(old.RS); if (old.RS) old.RS->Release();
|
||||
ctx->OMSetBlendState(old.BlendState, old.BlendFactor, old.SampleMask); if (old.BlendState) old.BlendState->Release();
|
||||
ctx->OMSetDepthStencilState(old.DepthStencilState, old.StencilRef); if (old.DepthStencilState) old.DepthStencilState->Release();
|
||||
ctx->PSSetShaderResources(0, 1, &old.PSShaderResource); if (old.PSShaderResource) old.PSShaderResource->Release();
|
||||
ctx->PSSetSamplers(0, 1, &old.PSSampler); if (old.PSSampler) old.PSSampler->Release();
|
||||
ctx->PSSetShader(old.PS, old.PSInstances, old.PSInstancesCount); if (old.PS) old.PS->Release();
|
||||
for (UINT i = 0; i < old.PSInstancesCount; i++) if (old.PSInstances[i]) old.PSInstances[i]->Release();
|
||||
ctx->VSSetShader(old.VS, old.VSInstances, old.VSInstancesCount); if (old.VS) old.VS->Release();
|
||||
ctx->VSSetConstantBuffers(0, 1, &old.VSConstantBuffer); if (old.VSConstantBuffer) old.VSConstantBuffer->Release();
|
||||
for (UINT i = 0; i < old.VSInstancesCount; i++) if (old.VSInstances[i]) old.VSInstances[i]->Release();
|
||||
ctx->RSSetState(old.RS);
|
||||
if (old.RS)
|
||||
old.RS->Release();
|
||||
ctx->OMSetBlendState(old.BlendState, old.BlendFactor, old.SampleMask);
|
||||
if (old.BlendState)
|
||||
old.BlendState->Release();
|
||||
ctx->OMSetDepthStencilState(old.DepthStencilState, old.StencilRef);
|
||||
if (old.DepthStencilState)
|
||||
old.DepthStencilState->Release();
|
||||
ctx->PSSetShaderResources(0, 1, &old.PSShaderResource);
|
||||
if (old.PSShaderResource)
|
||||
old.PSShaderResource->Release();
|
||||
ctx->PSSetSamplers(0, 1, &old.PSSampler);
|
||||
if (old.PSSampler)
|
||||
old.PSSampler->Release();
|
||||
ctx->PSSetShader(old.PS, old.PSInstances, old.PSInstancesCount);
|
||||
if (old.PS)
|
||||
old.PS->Release();
|
||||
for (UINT i = 0; i < old.PSInstancesCount; i++)
|
||||
if (old.PSInstances[i])
|
||||
old.PSInstances[i]->Release();
|
||||
ctx->VSSetShader(old.VS, old.VSInstances, old.VSInstancesCount);
|
||||
if (old.VS)
|
||||
old.VS->Release();
|
||||
ctx->VSSetConstantBuffers(0, 1, &old.VSConstantBuffer);
|
||||
if (old.VSConstantBuffer)
|
||||
old.VSConstantBuffer->Release();
|
||||
for (UINT i = 0; i < old.VSInstancesCount; i++)
|
||||
if (old.VSInstances[i])
|
||||
old.VSInstances[i]->Release();
|
||||
ctx->IASetPrimitiveTopology(old.PrimitiveTopology);
|
||||
ctx->IASetIndexBuffer(old.IndexBuffer, old.IndexBufferFormat, old.IndexBufferOffset); if (old.IndexBuffer) old.IndexBuffer->Release();
|
||||
ctx->IASetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset); if (old.VertexBuffer) old.VertexBuffer->Release();
|
||||
ctx->IASetInputLayout(old.InputLayout); if (old.InputLayout) old.InputLayout->Release();
|
||||
ctx->IASetIndexBuffer(old.IndexBuffer, old.IndexBufferFormat, old.IndexBufferOffset);
|
||||
if (old.IndexBuffer)
|
||||
old.IndexBuffer->Release();
|
||||
ctx->IASetVertexBuffers(0, 1, &old.VertexBuffer, &old.VertexBufferStride, &old.VertexBufferOffset);
|
||||
if (old.VertexBuffer)
|
||||
old.VertexBuffer->Release();
|
||||
ctx->IASetInputLayout(old.InputLayout);
|
||||
if (old.InputLayout)
|
||||
old.InputLayout->Release();
|
||||
}
|
||||
|
||||
static void ImGui_ImplDX11_CreateFontsTexture()
|
||||
|
|
@ -301,16 +338,17 @@ bool ImGui_ImplDX11_CreateDeviceObjects()
|
|||
if (g_pFontSampler)
|
||||
ImGui_ImplDX11_InvalidateDeviceObjects();
|
||||
|
||||
// By using D3DCompile() from <d3dcompiler.h> / d3dcompiler.lib, we introduce a dependency to a given version of d3dcompiler_XX.dll (see D3DCOMPILER_DLL_A)
|
||||
// If you would like to use this DX11 sample code but remove this dependency you can:
|
||||
// 1) compile once, save the compiled shader blobs into a file or source code and pass them to CreateVertexShader()/CreatePixelShader() [preferred solution]
|
||||
// 2) use code to detect any version of the DLL and grab a pointer to D3DCompile from the DLL.
|
||||
// By using D3DCompile() from <d3dcompiler.h> / d3dcompiler.lib, we introduce a dependency to a given version of
|
||||
// d3dcompiler_XX.dll (see D3DCOMPILER_DLL_A) If you would like to use this DX11 sample code but remove this
|
||||
// dependency you can:
|
||||
// 1) compile once, save the compiled shader blobs into a file or source code and pass them to
|
||||
// CreateVertexShader()/CreatePixelShader() [preferred solution] 2) use code to detect any version of the DLL and
|
||||
// grab a pointer to D3DCompile from the DLL.
|
||||
// See https://github.com/ocornut/imgui/pull/638 for sources and details.
|
||||
|
||||
// Create the vertex shader
|
||||
{
|
||||
static const char* vertexShader =
|
||||
"cbuffer vertexBuffer : register(b0) \
|
||||
static const char* vertexShader = "cbuffer vertexBuffer : register(b0) \
|
||||
{\
|
||||
float4x4 ProjectionMatrix; \
|
||||
};\
|
||||
|
|
@ -337,20 +375,29 @@ bool ImGui_ImplDX11_CreateDeviceObjects()
|
|||
return output;\
|
||||
}";
|
||||
|
||||
D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_4_0", 0, 0, &g_pVertexShaderBlob, NULL);
|
||||
if (g_pVertexShaderBlob == NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
|
||||
D3DCompile(vertexShader, strlen(vertexShader), NULL, NULL, NULL, "main", "vs_4_0", 0, 0, &g_pVertexShaderBlob,
|
||||
NULL);
|
||||
if (g_pVertexShaderBlob
|
||||
== NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const
|
||||
// char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
|
||||
return false;
|
||||
if (g_pd3dDevice->CreateVertexShader((DWORD*)g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), NULL, &g_pVertexShader) != S_OK)
|
||||
if (g_pd3dDevice->CreateVertexShader((DWORD*)g_pVertexShaderBlob->GetBufferPointer(),
|
||||
g_pVertexShaderBlob->GetBufferSize(), NULL, &g_pVertexShader)
|
||||
!= S_OK)
|
||||
return false;
|
||||
|
||||
// Create the input layout
|
||||
D3D11_INPUT_ELEMENT_DESC local_layout[] =
|
||||
{
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->pos), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->uv), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (size_t)(&((ImDrawVert*)0)->col), D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
D3D11_INPUT_ELEMENT_DESC local_layout[] = {
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->pos), D3D11_INPUT_PER_VERTEX_DATA,
|
||||
0 },
|
||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (size_t)(&((ImDrawVert*)0)->uv), D3D11_INPUT_PER_VERTEX_DATA,
|
||||
0 },
|
||||
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (size_t)(&((ImDrawVert*)0)->col), D3D11_INPUT_PER_VERTEX_DATA,
|
||||
0 },
|
||||
};
|
||||
if (g_pd3dDevice->CreateInputLayout(local_layout, 3, g_pVertexShaderBlob->GetBufferPointer(), g_pVertexShaderBlob->GetBufferSize(), &g_pInputLayout) != S_OK)
|
||||
if (g_pd3dDevice->CreateInputLayout(local_layout, 3, g_pVertexShaderBlob->GetBufferPointer(),
|
||||
g_pVertexShaderBlob->GetBufferSize(), &g_pInputLayout)
|
||||
!= S_OK)
|
||||
return false;
|
||||
|
||||
// Create the constant buffer
|
||||
|
|
@ -367,8 +414,7 @@ bool ImGui_ImplDX11_CreateDeviceObjects()
|
|||
|
||||
// Create the pixel shader
|
||||
{
|
||||
static const char* pixelShader =
|
||||
"struct PS_INPUT\
|
||||
static const char* pixelShader = "struct PS_INPUT\
|
||||
{\
|
||||
float4 pos : SV_POSITION;\
|
||||
float4 col : COLOR0;\
|
||||
|
|
@ -383,10 +429,15 @@ bool ImGui_ImplDX11_CreateDeviceObjects()
|
|||
return out_col; \
|
||||
}";
|
||||
|
||||
D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_4_0", 0, 0, &g_pPixelShaderBlob, NULL);
|
||||
if (g_pPixelShaderBlob == NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
|
||||
D3DCompile(pixelShader, strlen(pixelShader), NULL, NULL, NULL, "main", "ps_4_0", 0, 0, &g_pPixelShaderBlob,
|
||||
NULL);
|
||||
if (g_pPixelShaderBlob
|
||||
== NULL) // NB: Pass ID3D10Blob* pErrorBlob to D3DCompile() to get error showing in (const
|
||||
// char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob!
|
||||
return false;
|
||||
if (g_pd3dDevice->CreatePixelShader((DWORD*)g_pPixelShaderBlob->GetBufferPointer(), g_pPixelShaderBlob->GetBufferSize(), NULL, &g_pPixelShader) != S_OK)
|
||||
if (g_pd3dDevice->CreatePixelShader((DWORD*)g_pPixelShaderBlob->GetBufferPointer(),
|
||||
g_pPixelShaderBlob->GetBufferSize(), NULL, &g_pPixelShader)
|
||||
!= S_OK)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -425,7 +476,8 @@ bool ImGui_ImplDX11_CreateDeviceObjects()
|
|||
desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
|
||||
desc.DepthFunc = D3D11_COMPARISON_ALWAYS;
|
||||
desc.StencilEnable = false;
|
||||
desc.FrontFace.StencilFailOp = desc.FrontFace.StencilDepthFailOp = desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
|
||||
desc.FrontFace.StencilFailOp = desc.FrontFace.StencilDepthFailOp = desc.FrontFace.StencilPassOp =
|
||||
D3D11_STENCIL_OP_KEEP;
|
||||
desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
|
||||
desc.BackFace = desc.FrontFace;
|
||||
g_pd3dDevice->CreateDepthStencilState(&desc, &g_pDepthStencilState);
|
||||
|
|
@ -441,20 +493,73 @@ void ImGui_ImplDX11_InvalidateDeviceObjects()
|
|||
if (!g_pd3dDevice)
|
||||
return;
|
||||
|
||||
if (g_pFontSampler) { g_pFontSampler->Release(); g_pFontSampler = NULL; }
|
||||
if (g_pFontTextureView) { g_pFontTextureView->Release(); g_pFontTextureView = NULL; ImGui::GetIO().Fonts->TexID = NULL; } // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well.
|
||||
if (g_pIB) { g_pIB->Release(); g_pIB = NULL; }
|
||||
if (g_pVB) { g_pVB->Release(); g_pVB = NULL; }
|
||||
if (g_pFontSampler)
|
||||
{
|
||||
g_pFontSampler->Release();
|
||||
g_pFontSampler = NULL;
|
||||
}
|
||||
if (g_pFontTextureView)
|
||||
{
|
||||
g_pFontTextureView->Release();
|
||||
g_pFontTextureView = NULL;
|
||||
ImGui::GetIO().Fonts->TexID = NULL;
|
||||
} // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well.
|
||||
if (g_pIB)
|
||||
{
|
||||
g_pIB->Release();
|
||||
g_pIB = NULL;
|
||||
}
|
||||
if (g_pVB)
|
||||
{
|
||||
g_pVB->Release();
|
||||
g_pVB = NULL;
|
||||
}
|
||||
|
||||
if (g_pBlendState) { g_pBlendState->Release(); g_pBlendState = NULL; }
|
||||
if (g_pDepthStencilState) { g_pDepthStencilState->Release(); g_pDepthStencilState = NULL; }
|
||||
if (g_pRasterizerState) { g_pRasterizerState->Release(); g_pRasterizerState = NULL; }
|
||||
if (g_pPixelShader) { g_pPixelShader->Release(); g_pPixelShader = NULL; }
|
||||
if (g_pPixelShaderBlob) { g_pPixelShaderBlob->Release(); g_pPixelShaderBlob = NULL; }
|
||||
if (g_pVertexConstantBuffer) { g_pVertexConstantBuffer->Release(); g_pVertexConstantBuffer = NULL; }
|
||||
if (g_pInputLayout) { g_pInputLayout->Release(); g_pInputLayout = NULL; }
|
||||
if (g_pVertexShader) { g_pVertexShader->Release(); g_pVertexShader = NULL; }
|
||||
if (g_pVertexShaderBlob) { g_pVertexShaderBlob->Release(); g_pVertexShaderBlob = NULL; }
|
||||
if (g_pBlendState)
|
||||
{
|
||||
g_pBlendState->Release();
|
||||
g_pBlendState = NULL;
|
||||
}
|
||||
if (g_pDepthStencilState)
|
||||
{
|
||||
g_pDepthStencilState->Release();
|
||||
g_pDepthStencilState = NULL;
|
||||
}
|
||||
if (g_pRasterizerState)
|
||||
{
|
||||
g_pRasterizerState->Release();
|
||||
g_pRasterizerState = NULL;
|
||||
}
|
||||
if (g_pPixelShader)
|
||||
{
|
||||
g_pPixelShader->Release();
|
||||
g_pPixelShader = NULL;
|
||||
}
|
||||
if (g_pPixelShaderBlob)
|
||||
{
|
||||
g_pPixelShaderBlob->Release();
|
||||
g_pPixelShaderBlob = NULL;
|
||||
}
|
||||
if (g_pVertexConstantBuffer)
|
||||
{
|
||||
g_pVertexConstantBuffer->Release();
|
||||
g_pVertexConstantBuffer = NULL;
|
||||
}
|
||||
if (g_pInputLayout)
|
||||
{
|
||||
g_pInputLayout->Release();
|
||||
g_pInputLayout = NULL;
|
||||
}
|
||||
if (g_pVertexShader)
|
||||
{
|
||||
g_pVertexShader->Release();
|
||||
g_pVertexShader = NULL;
|
||||
}
|
||||
if (g_pVertexShaderBlob)
|
||||
{
|
||||
g_pVertexShaderBlob->Release();
|
||||
g_pVertexShaderBlob = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context)
|
||||
|
|
@ -475,8 +580,10 @@ bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_co
|
|||
g_pd3dDeviceContext = device_context;
|
||||
g_pFactory = pFactory;
|
||||
}
|
||||
if (pDXGIDevice) pDXGIDevice->Release();
|
||||
if (pDXGIAdapter) pDXGIAdapter->Release();
|
||||
if (pDXGIDevice)
|
||||
pDXGIDevice->Release();
|
||||
if (pDXGIAdapter)
|
||||
pDXGIAdapter->Release();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -484,7 +591,11 @@ bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_co
|
|||
void ImGui_ImplDX11_Shutdown()
|
||||
{
|
||||
ImGui_ImplDX11_InvalidateDeviceObjects();
|
||||
if (g_pFactory) { g_pFactory->Release(); g_pFactory = NULL; }
|
||||
if (g_pFactory)
|
||||
{
|
||||
g_pFactory->Release();
|
||||
g_pFactory = NULL;
|
||||
}
|
||||
g_pd3dDevice = NULL;
|
||||
g_pd3dDeviceContext = NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,16 +18,14 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#include <thread>
|
||||
#include <3rd-party/curl/curl.h> // CURL
|
||||
#include <codecvt>
|
||||
|
||||
#include <kiwano-network/HttpClient.h>
|
||||
#include <kiwano-network/HttpRequest.h>
|
||||
#include <kiwano-network/HttpResponse.hpp>
|
||||
#include <kiwano-network/HttpClient.h>
|
||||
|
||||
#include <kiwano/core/Logger.h>
|
||||
#include <kiwano/platform/Application.h>
|
||||
#include <3rd-party/curl/curl.h> // CURL
|
||||
#include <thread>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
|
@ -104,7 +102,8 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
bool Init(HttpClient* client, Vector<ByteString> const& headers, ByteString const& url, ByteString* response_data, ByteString* response_header, char* error_buffer)
|
||||
bool Init(HttpClient* client, Vector<ByteString> const& headers, ByteString const& url, ByteString* response_data,
|
||||
ByteString* response_header, char* error_buffer)
|
||||
{
|
||||
if (!SetOption(CURLOPT_ERRORBUFFER, error_buffer))
|
||||
return false;
|
||||
|
|
@ -114,13 +113,15 @@ namespace
|
|||
return false;
|
||||
|
||||
const auto ssl_ca_file = wide_to_string(client->GetSSLVerification());
|
||||
if (ssl_ca_file.empty()) {
|
||||
if (ssl_ca_file.empty())
|
||||
{
|
||||
if (!SetOption(CURLOPT_SSL_VERIFYPEER, 0L))
|
||||
return false;
|
||||
if (!SetOption(CURLOPT_SSL_VERIFYHOST, 0L))
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
if (!SetOption(CURLOPT_SSL_VERIFYPEER, 1L))
|
||||
return false;
|
||||
if (!SetOption(CURLOPT_SSL_VERIFYHOST, 2L))
|
||||
|
|
@ -145,10 +146,8 @@ namespace
|
|||
return false;
|
||||
}
|
||||
|
||||
return SetOption(CURLOPT_URL, url.c_str())
|
||||
&& SetOption(CURLOPT_WRITEFUNCTION, write_data)
|
||||
&& SetOption(CURLOPT_WRITEDATA, response_data)
|
||||
&& SetOption(CURLOPT_HEADERFUNCTION, write_data)
|
||||
return SetOption(CURLOPT_URL, url.c_str()) && SetOption(CURLOPT_WRITEFUNCTION, write_data)
|
||||
&& SetOption(CURLOPT_WRITEDATA, response_data) && SetOption(CURLOPT_HEADERFUNCTION, write_data)
|
||||
&& SetOption(CURLOPT_HEADERDATA, response_header);
|
||||
}
|
||||
|
||||
|
|
@ -168,70 +167,43 @@ namespace
|
|||
}
|
||||
|
||||
public:
|
||||
static inline bool GetRequest(
|
||||
HttpClient* client,
|
||||
Vector<ByteString> const& headers,
|
||||
ByteString const& url,
|
||||
long* response_code,
|
||||
ByteString* response_data,
|
||||
ByteString* response_header,
|
||||
static inline bool GetRequest(HttpClient* client, Vector<ByteString> const& headers, ByteString const& url,
|
||||
long* response_code, ByteString* response_data, ByteString* response_header,
|
||||
char* error_buffer)
|
||||
{
|
||||
Curl curl;
|
||||
return curl.Init(client, headers, url, response_data, response_header, error_buffer)
|
||||
&& curl.SetOption(CURLOPT_FOLLOWLOCATION, true)
|
||||
&& curl.Perform(response_code);
|
||||
&& curl.SetOption(CURLOPT_FOLLOWLOCATION, true) && curl.Perform(response_code);
|
||||
}
|
||||
|
||||
static inline bool PostRequest(
|
||||
HttpClient* client,
|
||||
Vector<ByteString> const& headers,
|
||||
ByteString const& url,
|
||||
ByteString const& request_data,
|
||||
long* response_code,
|
||||
ByteString* response_data,
|
||||
ByteString* response_header,
|
||||
char* error_buffer)
|
||||
static inline bool PostRequest(HttpClient* client, Vector<ByteString> const& headers, ByteString const& url,
|
||||
ByteString const& request_data, long* response_code, ByteString* response_data,
|
||||
ByteString* response_header, char* error_buffer)
|
||||
{
|
||||
Curl curl;
|
||||
return curl.Init(client, headers, url, response_data, response_header, error_buffer)
|
||||
&& curl.SetOption(CURLOPT_POST, 1)
|
||||
&& curl.SetOption(CURLOPT_POSTFIELDS, request_data.c_str())
|
||||
&& curl.SetOption(CURLOPT_POSTFIELDSIZE, request_data.size())
|
||||
&& curl.Perform(response_code);
|
||||
&& curl.SetOption(CURLOPT_POST, 1) && curl.SetOption(CURLOPT_POSTFIELDS, request_data.c_str())
|
||||
&& curl.SetOption(CURLOPT_POSTFIELDSIZE, request_data.size()) && curl.Perform(response_code);
|
||||
}
|
||||
|
||||
static inline bool PutRequest(
|
||||
HttpClient* client,
|
||||
Vector<ByteString> const& headers,
|
||||
ByteString const& url,
|
||||
ByteString const& request_data,
|
||||
long* response_code,
|
||||
ByteString* response_data,
|
||||
ByteString* response_header,
|
||||
char* error_buffer)
|
||||
static inline bool PutRequest(HttpClient* client, Vector<ByteString> const& headers, ByteString const& url,
|
||||
ByteString const& request_data, long* response_code, ByteString* response_data,
|
||||
ByteString* response_header, char* error_buffer)
|
||||
{
|
||||
Curl curl;
|
||||
return curl.Init(client, headers, url, response_data, response_header, error_buffer)
|
||||
&& curl.SetOption(CURLOPT_CUSTOMREQUEST, "PUT")
|
||||
&& curl.SetOption(CURLOPT_POSTFIELDS, request_data.c_str())
|
||||
&& curl.SetOption(CURLOPT_POSTFIELDSIZE, request_data.size())
|
||||
&& curl.Perform(response_code);
|
||||
&& curl.SetOption(CURLOPT_POSTFIELDSIZE, request_data.size()) && curl.Perform(response_code);
|
||||
}
|
||||
|
||||
static inline bool DeleteRequest(
|
||||
HttpClient* client,
|
||||
Vector<ByteString> const& headers,
|
||||
ByteString const& url,
|
||||
long* response_code,
|
||||
ByteString* response_data,
|
||||
ByteString* response_header,
|
||||
static inline bool DeleteRequest(HttpClient* client, Vector<ByteString> const& headers, ByteString const& url,
|
||||
long* response_code, ByteString* response_data, ByteString* response_header,
|
||||
char* error_buffer)
|
||||
{
|
||||
Curl curl;
|
||||
return curl.Init(client, headers, url, response_data, response_header, error_buffer)
|
||||
&& curl.SetOption(CURLOPT_CUSTOMREQUEST, "DELETE")
|
||||
&& curl.SetOption(CURLOPT_FOLLOWLOCATION, true)
|
||||
&& curl.SetOption(CURLOPT_CUSTOMREQUEST, "DELETE") && curl.SetOption(CURLOPT_FOLLOWLOCATION, true)
|
||||
&& curl.Perform(response_code);
|
||||
}
|
||||
|
||||
|
|
@ -239,7 +211,7 @@ namespace
|
|||
CURL* curl_;
|
||||
curl_slist* curl_headers_;
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -326,10 +298,12 @@ namespace kiwano
|
|||
ok = Curl::GetRequest(this, headers, url, &response_code, &response_data, &response_header, error_message);
|
||||
break;
|
||||
case HttpRequest::Type::Post:
|
||||
ok = Curl::PostRequest(this, headers, url, data, &response_code, &response_data, &response_header, error_message);
|
||||
ok = Curl::PostRequest(this, headers, url, data, &response_code, &response_data, &response_header,
|
||||
error_message);
|
||||
break;
|
||||
case HttpRequest::Type::Put:
|
||||
ok = Curl::PutRequest(this, headers, url, data, &response_code, &response_data, &response_header, error_message);
|
||||
ok =
|
||||
Curl::PutRequest(this, headers, url, data, &response_code, &response_data, &response_header, error_message);
|
||||
break;
|
||||
case HttpRequest::Type::Delete:
|
||||
ok = Curl::DeleteRequest(this, headers, url, &response_code, &response_data, &response_header, error_message);
|
||||
|
|
@ -377,5 +351,5 @@ namespace kiwano
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace network
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <condition_variable>
|
||||
#include <kiwano/core/Common.h>
|
||||
#include <kiwano/core/Component.h>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -110,7 +110,6 @@ namespace kiwano
|
|||
|
||||
/** @} */
|
||||
|
||||
|
||||
inline void HttpClient::SetTimeoutForConnect(Duration timeout)
|
||||
{
|
||||
timeout_for_connect_ = timeout;
|
||||
|
|
@ -141,5 +140,5 @@ namespace kiwano
|
|||
return ssl_verification_;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace network
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -30,5 +30,5 @@ namespace kiwano
|
|||
SetHeader(L"Content-Type", L"application/json;charset=UTF-8");
|
||||
data_ = json.dump();
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace network
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -40,8 +40,7 @@ namespace kiwano
|
|||
* \~chinese
|
||||
* @brief HTTPÇëÇó
|
||||
*/
|
||||
class KGE_API HttpRequest
|
||||
: public virtual ObjectBase
|
||||
class KGE_API HttpRequest : public virtual ObjectBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -125,32 +124,74 @@ namespace kiwano
|
|||
|
||||
/** @} */
|
||||
|
||||
inline HttpRequest::HttpRequest() : type_(Type::Unknown) {}
|
||||
|
||||
inline HttpRequest::HttpRequest(Type type) : type_(type) {}
|
||||
|
||||
inline void HttpRequest::SetUrl(String const& url) { url_ = url; }
|
||||
|
||||
inline String const& HttpRequest::GetUrl() const { return url_; }
|
||||
|
||||
inline void HttpRequest::SetType(Type type) { type_ = type; }
|
||||
|
||||
inline HttpRequest::Type HttpRequest::GetType() const { return type_; }
|
||||
|
||||
inline void HttpRequest::SetData(String const& data) { data_ = data; }
|
||||
|
||||
inline String const& HttpRequest::GetData() const { return data_; }
|
||||
|
||||
inline void HttpRequest::SetHeaders(Map<String, String> const& headers) { headers_ = headers; }
|
||||
|
||||
inline void HttpRequest::SetHeader(String const& field, String const& content) { headers_[field] = content; }
|
||||
|
||||
inline Map<String, String>& HttpRequest::GetHeaders() { return headers_; }
|
||||
|
||||
inline String const& HttpRequest::GetHeader(String const& header) const { return headers_.at(header); }
|
||||
|
||||
inline void HttpRequest::SetResponseCallback(ResponseCallback const& callback) { response_cb_ = callback; }
|
||||
|
||||
inline HttpRequest::ResponseCallback const& HttpRequest::GetResponseCallback() const { return response_cb_; }
|
||||
inline HttpRequest::HttpRequest()
|
||||
: type_(Type::Unknown)
|
||||
{
|
||||
}
|
||||
|
||||
inline HttpRequest::HttpRequest(Type type)
|
||||
: type_(type)
|
||||
{
|
||||
}
|
||||
|
||||
inline void HttpRequest::SetUrl(String const& url)
|
||||
{
|
||||
url_ = url;
|
||||
}
|
||||
|
||||
inline String const& HttpRequest::GetUrl() const
|
||||
{
|
||||
return url_;
|
||||
}
|
||||
|
||||
inline void HttpRequest::SetType(Type type)
|
||||
{
|
||||
type_ = type;
|
||||
}
|
||||
|
||||
inline HttpRequest::Type HttpRequest::GetType() const
|
||||
{
|
||||
return type_;
|
||||
}
|
||||
|
||||
inline void HttpRequest::SetData(String const& data)
|
||||
{
|
||||
data_ = data;
|
||||
}
|
||||
|
||||
inline String const& HttpRequest::GetData() const
|
||||
{
|
||||
return data_;
|
||||
}
|
||||
|
||||
inline void HttpRequest::SetHeaders(Map<String, String> const& headers)
|
||||
{
|
||||
headers_ = headers;
|
||||
}
|
||||
|
||||
inline void HttpRequest::SetHeader(String const& field, String const& content)
|
||||
{
|
||||
headers_[field] = content;
|
||||
}
|
||||
|
||||
inline Map<String, String>& HttpRequest::GetHeaders()
|
||||
{
|
||||
return headers_;
|
||||
}
|
||||
|
||||
inline String const& HttpRequest::GetHeader(String const& header) const
|
||||
{
|
||||
return headers_.at(header);
|
||||
}
|
||||
|
||||
inline void HttpRequest::SetResponseCallback(ResponseCallback const& callback)
|
||||
{
|
||||
response_cb_ = callback;
|
||||
}
|
||||
|
||||
inline HttpRequest::ResponseCallback const& HttpRequest::GetResponseCallback() const
|
||||
{
|
||||
return response_cb_;
|
||||
}
|
||||
} // namespace network
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -36,8 +36,7 @@ namespace kiwano
|
|||
* \~chinese
|
||||
* @brief HTTPÏìÓ¦
|
||||
*/
|
||||
class KGE_API HttpResponse
|
||||
: public virtual ObjectBase
|
||||
class KGE_API HttpResponse : public virtual ObjectBase
|
||||
{
|
||||
public:
|
||||
HttpResponse(HttpRequestPtr request);
|
||||
|
|
@ -98,28 +97,66 @@ namespace kiwano
|
|||
|
||||
/** @} */
|
||||
|
||||
inline HttpResponse::HttpResponse(HttpRequestPtr request) : request_(request), succeed_(false), response_code_(0) {}
|
||||
|
||||
inline HttpRequestPtr HttpResponse::GetRequest() const { return request_; }
|
||||
|
||||
inline void HttpResponse::SetSucceed(bool succeed) { succeed_ = succeed; }
|
||||
|
||||
inline bool HttpResponse::IsSucceed() const { return succeed_; }
|
||||
|
||||
inline void HttpResponse::SetResponseCode(long response_code) { response_code_ = response_code; }
|
||||
|
||||
inline long HttpResponse::GetResponseCode() const { return response_code_; }
|
||||
|
||||
inline void HttpResponse::SetHeader(String const& response_header) { response_header_ = response_header; }
|
||||
|
||||
inline String HttpResponse::GetHeader() const { return response_header_; }
|
||||
|
||||
inline void HttpResponse::SetData(String const& response_data) { response_data_ = response_data; }
|
||||
|
||||
inline String const& HttpResponse::GetData() const { return response_data_; }
|
||||
|
||||
inline void HttpResponse::SetError(String const& error_buffer) { error_buffer_ = error_buffer; }
|
||||
|
||||
inline String const& HttpResponse::GetError() const { return error_buffer_; }
|
||||
inline HttpResponse::HttpResponse(HttpRequestPtr request)
|
||||
: request_(request)
|
||||
, succeed_(false)
|
||||
, response_code_(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline HttpRequestPtr HttpResponse::GetRequest() const
|
||||
{
|
||||
return request_;
|
||||
}
|
||||
|
||||
inline void HttpResponse::SetSucceed(bool succeed)
|
||||
{
|
||||
succeed_ = succeed;
|
||||
}
|
||||
|
||||
inline bool HttpResponse::IsSucceed() const
|
||||
{
|
||||
return succeed_;
|
||||
}
|
||||
|
||||
inline void HttpResponse::SetResponseCode(long response_code)
|
||||
{
|
||||
response_code_ = response_code;
|
||||
}
|
||||
|
||||
inline long HttpResponse::GetResponseCode() const
|
||||
{
|
||||
return response_code_;
|
||||
}
|
||||
|
||||
inline void HttpResponse::SetHeader(String const& response_header)
|
||||
{
|
||||
response_header_ = response_header;
|
||||
}
|
||||
|
||||
inline String HttpResponse::GetHeader() const
|
||||
{
|
||||
return response_header_;
|
||||
}
|
||||
|
||||
inline void HttpResponse::SetData(String const& response_data)
|
||||
{
|
||||
response_data_ = response_data;
|
||||
}
|
||||
|
||||
inline String const& HttpResponse::GetData() const
|
||||
{
|
||||
return response_data_;
|
||||
}
|
||||
|
||||
inline void HttpResponse::SetError(String const& error_buffer)
|
||||
{
|
||||
error_buffer_ = error_buffer;
|
||||
}
|
||||
|
||||
inline String const& HttpResponse::GetError() const
|
||||
{
|
||||
return error_buffer_;
|
||||
}
|
||||
} // namespace network
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -20,6 +20,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <kiwano-network/HttpClient.h>
|
||||
#include <kiwano-network/HttpRequest.h>
|
||||
#include <kiwano-network/HttpResponse.hpp>
|
||||
#include <kiwano-network/HttpClient.h>
|
||||
|
|
|
|||
|
|
@ -158,9 +158,12 @@ namespace kiwano
|
|||
b2MassData data;
|
||||
body_->GetMassData(&data);
|
||||
|
||||
if (mass) *mass = data.mass;
|
||||
if (center) *center = world_->World2Stage(data.center);
|
||||
if (inertia) *inertia = data.I;
|
||||
if (mass)
|
||||
*mass = data.mass;
|
||||
if (center)
|
||||
*center = world_->World2Stage(data.center);
|
||||
if (inertia)
|
||||
*inertia = data.I;
|
||||
}
|
||||
|
||||
void Body::SetMassData(float mass, Point const& center, float inertia)
|
||||
|
|
@ -277,17 +280,11 @@ namespace kiwano
|
|||
{
|
||||
if (world_)
|
||||
{
|
||||
body_->SetTransform(
|
||||
world_->Stage2World(actor_->GetPosition()),
|
||||
math::Degree2Radian(actor_->GetRotation())
|
||||
);
|
||||
body_->SetTransform(world_->Stage2World(actor_->GetPosition()), math::Degree2Radian(actor_->GetRotation()));
|
||||
}
|
||||
else
|
||||
{
|
||||
body_->SetTransform(
|
||||
Stage2World(actor_->GetPosition()),
|
||||
math::Degree2Radian(actor_->GetRotation())
|
||||
);
|
||||
body_->SetTransform(Stage2World(actor_->GetPosition()), math::Degree2Radian(actor_->GetRotation()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -301,5 +298,5 @@ namespace kiwano
|
|||
fixture->SetFilterData(filter);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace physics
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano-physics/helper.h>
|
||||
#include <kiwano-physics/Shape.h>
|
||||
#include <kiwano-physics/Fixture.h>
|
||||
#include <kiwano-physics/ContactEdge.h>
|
||||
#include <kiwano-physics/Fixture.h>
|
||||
#include <kiwano-physics/Shape.h>
|
||||
#include <kiwano-physics/helper.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -39,8 +39,7 @@ namespace kiwano
|
|||
|
||||
/// \~chinese
|
||||
/// @brief ÎïÌå
|
||||
class KGE_API Body
|
||||
: public virtual ObjectBase
|
||||
class KGE_API Body : public virtual ObjectBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -323,62 +322,168 @@ namespace kiwano
|
|||
|
||||
/** @} */
|
||||
|
||||
inline bool Body::InitBody(World* world, ActorPtr actor) { return InitBody(world, actor.get()); }
|
||||
|
||||
inline FixtureList Body::GetFixtureList() const { KGE_ASSERT(body_); return FixtureList(Fixture(body_->GetFixtureList())); }
|
||||
|
||||
inline ContactEdgeList Body::GetContactList() const { KGE_ASSERT(body_); return ContactEdgeList(ContactEdge(body_->GetContactList())); }
|
||||
|
||||
inline uint16_t Body::GetCategoryBits() const { return category_bits_; }
|
||||
|
||||
inline uint16_t Body::GetMaskBits() const { return mask_bits_; }
|
||||
|
||||
inline int16_t Body::GetGroupIndex() const { return group_index_; }
|
||||
|
||||
inline float Body::GetBodyRotation() const { KGE_ASSERT(body_); return math::Radian2Degree(body_->GetAngle()); }
|
||||
|
||||
inline void Body::SetBodyRotation(float angle) { SetBodyTransform(GetBodyPosition(), angle); }
|
||||
|
||||
inline void Body::SetBodyPosition(Point const& pos) { SetBodyTransform(pos, GetBodyRotation()); }
|
||||
|
||||
inline float Body::GetMass() const { KGE_ASSERT(body_); return body_->GetMass(); }
|
||||
|
||||
inline float Body::GetInertia() const { KGE_ASSERT(body_); return body_->GetInertia(); }
|
||||
|
||||
inline Body::Type Body::GetType() const { KGE_ASSERT(body_); return Type(body_->GetType()); }
|
||||
|
||||
inline void Body::SetType(Type type) { KGE_ASSERT(body_); body_->SetType(static_cast<b2BodyType>(type)); }
|
||||
|
||||
inline float Body::GetGravityScale() const { KGE_ASSERT(body_); return body_->GetGravityScale(); }
|
||||
|
||||
inline void Body::SetGravityScale(float scale) { KGE_ASSERT(body_); body_->SetGravityScale(scale); }
|
||||
|
||||
inline bool Body::IsIgnoreRotation() const { KGE_ASSERT(body_); return body_->IsFixedRotation(); }
|
||||
|
||||
inline void Body::SetIgnoreRotation(bool flag) { KGE_ASSERT(body_); body_->SetFixedRotation(flag); }
|
||||
|
||||
inline bool Body::IsBullet() const { KGE_ASSERT(body_); return body_->IsBullet(); }
|
||||
|
||||
inline void Body::SetBullet(bool flag) { KGE_ASSERT(body_); body_->SetBullet(flag); }
|
||||
|
||||
inline bool Body::IsAwake() const { KGE_ASSERT(body_); return body_->IsAwake(); }
|
||||
|
||||
inline void Body::SetAwake(bool flag) { KGE_ASSERT(body_); body_->SetAwake(flag); }
|
||||
|
||||
inline bool Body::IsSleepingAllowed() const { KGE_ASSERT(body_); return body_->IsSleepingAllowed(); }
|
||||
|
||||
inline void Body::SetSleepingAllowed(bool flag) { KGE_ASSERT(body_); body_->SetSleepingAllowed(flag); }
|
||||
|
||||
inline bool Body::IsActive() const { KGE_ASSERT(body_); return body_->IsActive(); }
|
||||
|
||||
inline void Body::SetActive(bool flag) { KGE_ASSERT(body_); body_->SetActive(flag); }
|
||||
|
||||
inline Actor* Body::GetActor() const { return actor_; }
|
||||
|
||||
inline void Body::SetActor(Actor* actor) { actor_ = actor; }
|
||||
|
||||
inline b2Body* Body::GetB2Body() const { return body_; }
|
||||
|
||||
inline World* Body::GetWorld() const { return world_; }
|
||||
inline bool Body::InitBody(World* world, ActorPtr actor)
|
||||
{
|
||||
return InitBody(world, actor.get());
|
||||
}
|
||||
|
||||
inline FixtureList Body::GetFixtureList() const
|
||||
{
|
||||
KGE_ASSERT(body_);
|
||||
return FixtureList(Fixture(body_->GetFixtureList()));
|
||||
}
|
||||
|
||||
inline ContactEdgeList Body::GetContactList() const
|
||||
{
|
||||
KGE_ASSERT(body_);
|
||||
return ContactEdgeList(ContactEdge(body_->GetContactList()));
|
||||
}
|
||||
|
||||
inline uint16_t Body::GetCategoryBits() const
|
||||
{
|
||||
return category_bits_;
|
||||
}
|
||||
|
||||
inline uint16_t Body::GetMaskBits() const
|
||||
{
|
||||
return mask_bits_;
|
||||
}
|
||||
|
||||
inline int16_t Body::GetGroupIndex() const
|
||||
{
|
||||
return group_index_;
|
||||
}
|
||||
|
||||
inline float Body::GetBodyRotation() const
|
||||
{
|
||||
KGE_ASSERT(body_);
|
||||
return math::Radian2Degree(body_->GetAngle());
|
||||
}
|
||||
|
||||
inline void Body::SetBodyRotation(float angle)
|
||||
{
|
||||
SetBodyTransform(GetBodyPosition(), angle);
|
||||
}
|
||||
|
||||
inline void Body::SetBodyPosition(Point const& pos)
|
||||
{
|
||||
SetBodyTransform(pos, GetBodyRotation());
|
||||
}
|
||||
|
||||
inline float Body::GetMass() const
|
||||
{
|
||||
KGE_ASSERT(body_);
|
||||
return body_->GetMass();
|
||||
}
|
||||
|
||||
inline float Body::GetInertia() const
|
||||
{
|
||||
KGE_ASSERT(body_);
|
||||
return body_->GetInertia();
|
||||
}
|
||||
|
||||
inline Body::Type Body::GetType() const
|
||||
{
|
||||
KGE_ASSERT(body_);
|
||||
return Type(body_->GetType());
|
||||
}
|
||||
|
||||
inline void Body::SetType(Type type)
|
||||
{
|
||||
KGE_ASSERT(body_);
|
||||
body_->SetType(static_cast<b2BodyType>(type));
|
||||
}
|
||||
|
||||
inline float Body::GetGravityScale() const
|
||||
{
|
||||
KGE_ASSERT(body_);
|
||||
return body_->GetGravityScale();
|
||||
}
|
||||
|
||||
inline void Body::SetGravityScale(float scale)
|
||||
{
|
||||
KGE_ASSERT(body_);
|
||||
body_->SetGravityScale(scale);
|
||||
}
|
||||
|
||||
inline bool Body::IsIgnoreRotation() const
|
||||
{
|
||||
KGE_ASSERT(body_);
|
||||
return body_->IsFixedRotation();
|
||||
}
|
||||
|
||||
inline void Body::SetIgnoreRotation(bool flag)
|
||||
{
|
||||
KGE_ASSERT(body_);
|
||||
body_->SetFixedRotation(flag);
|
||||
}
|
||||
|
||||
inline bool Body::IsBullet() const
|
||||
{
|
||||
KGE_ASSERT(body_);
|
||||
return body_->IsBullet();
|
||||
}
|
||||
|
||||
inline void Body::SetBullet(bool flag)
|
||||
{
|
||||
KGE_ASSERT(body_);
|
||||
body_->SetBullet(flag);
|
||||
}
|
||||
|
||||
inline bool Body::IsAwake() const
|
||||
{
|
||||
KGE_ASSERT(body_);
|
||||
return body_->IsAwake();
|
||||
}
|
||||
|
||||
inline void Body::SetAwake(bool flag)
|
||||
{
|
||||
KGE_ASSERT(body_);
|
||||
body_->SetAwake(flag);
|
||||
}
|
||||
|
||||
inline bool Body::IsSleepingAllowed() const
|
||||
{
|
||||
KGE_ASSERT(body_);
|
||||
return body_->IsSleepingAllowed();
|
||||
}
|
||||
|
||||
inline void Body::SetSleepingAllowed(bool flag)
|
||||
{
|
||||
KGE_ASSERT(body_);
|
||||
body_->SetSleepingAllowed(flag);
|
||||
}
|
||||
|
||||
inline bool Body::IsActive() const
|
||||
{
|
||||
KGE_ASSERT(body_);
|
||||
return body_->IsActive();
|
||||
}
|
||||
|
||||
inline void Body::SetActive(bool flag)
|
||||
{
|
||||
KGE_ASSERT(body_);
|
||||
body_->SetActive(flag);
|
||||
}
|
||||
|
||||
inline Actor* Body::GetActor() const
|
||||
{
|
||||
return actor_;
|
||||
}
|
||||
|
||||
inline void Body::SetActor(Actor* actor)
|
||||
{
|
||||
actor_ = actor;
|
||||
}
|
||||
|
||||
inline b2Body* Body::GetB2Body() const
|
||||
{
|
||||
return body_;
|
||||
}
|
||||
|
||||
inline World* Body::GetWorld() const
|
||||
{
|
||||
return world_;
|
||||
}
|
||||
} // namespace physics
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#include <kiwano-physics/Contact.h>
|
||||
#include <kiwano-physics/Body.h>
|
||||
#include <kiwano-physics/Contact.h>
|
||||
#include <kiwano-physics/World.h>
|
||||
|
||||
namespace kiwano
|
||||
|
|
@ -86,5 +86,5 @@ namespace kiwano
|
|||
return world->World2Stage(contact_->GetTangentSpeed());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace physics
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano-physics/helper.h>
|
||||
#include <kiwano-physics/Fixture.h>
|
||||
#include <kiwano-physics/helper.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -115,15 +115,12 @@ namespace kiwano
|
|||
b2Contact* contact_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 物理接触列表
|
||||
class ContactList
|
||||
: public List<Contact>
|
||||
class ContactList : public List<Contact>
|
||||
{
|
||||
template <typename _Ty>
|
||||
class IteratorImpl
|
||||
: public std::iterator<std::forward_iterator_tag, _Ty>
|
||||
class IteratorImpl : public std::iterator<std::forward_iterator_tag, _Ty>
|
||||
{
|
||||
using herit = std::iterator<std::forward_iterator_tag, _Ty>;
|
||||
|
||||
|
|
@ -175,9 +172,7 @@ namespace kiwano
|
|||
using iterator = IteratorImpl<value_type>;
|
||||
using const_iterator = IteratorImpl<const value_type>;
|
||||
|
||||
inline ContactList()
|
||||
{
|
||||
}
|
||||
inline ContactList() {}
|
||||
|
||||
inline ContactList(const value_type& first)
|
||||
: first_(first)
|
||||
|
|
@ -230,21 +225,71 @@ namespace kiwano
|
|||
|
||||
/** @} */
|
||||
|
||||
|
||||
inline bool Contact::IsValid() const { return contact_ != nullptr;}
|
||||
inline bool Contact::IsTouching() const { KGE_ASSERT(contact_); return contact_->IsTouching(); }
|
||||
inline void Contact::SetEnabled(bool flag) { KGE_ASSERT(contact_); contact_->SetEnabled(flag); }
|
||||
inline bool Contact::IsEnabled() const { KGE_ASSERT(contact_); return contact_->IsEnabled(); }
|
||||
inline void Contact::SetFriction(float friction) { KGE_ASSERT(contact_); contact_->SetFriction(friction); }
|
||||
inline float Contact::GetFriction() const { KGE_ASSERT(contact_); return contact_->GetFriction(); }
|
||||
inline void Contact::ResetFriction() { KGE_ASSERT(contact_); contact_->ResetFriction(); }
|
||||
inline void Contact::SetRestitution(float restitution) { KGE_ASSERT(contact_); contact_->SetRestitution(restitution); }
|
||||
inline float Contact::GetRestitution() const { KGE_ASSERT(contact_); return contact_->GetRestitution(); }
|
||||
inline void Contact::ResetRestitution() { KGE_ASSERT(contact_); contact_->ResetRestitution(); }
|
||||
inline b2Contact* Contact::GetB2Contact() const { return contact_; }
|
||||
inline void Contact::SetB2Contact(b2Contact* contact) { contact_ = contact; }
|
||||
inline bool Contact::operator==(const Contact& rhs) const { return contact_ == rhs.contact_; }
|
||||
inline bool Contact::operator!=(const Contact& rhs) const { return contact_ != rhs.contact_; }
|
||||
|
||||
inline bool Contact::IsValid() const
|
||||
{
|
||||
return contact_ != nullptr;
|
||||
}
|
||||
inline bool Contact::IsTouching() const
|
||||
{
|
||||
KGE_ASSERT(contact_);
|
||||
return contact_->IsTouching();
|
||||
}
|
||||
inline void Contact::SetEnabled(bool flag)
|
||||
{
|
||||
KGE_ASSERT(contact_);
|
||||
contact_->SetEnabled(flag);
|
||||
}
|
||||
inline bool Contact::IsEnabled() const
|
||||
{
|
||||
KGE_ASSERT(contact_);
|
||||
return contact_->IsEnabled();
|
||||
}
|
||||
inline void Contact::SetFriction(float friction)
|
||||
{
|
||||
KGE_ASSERT(contact_);
|
||||
contact_->SetFriction(friction);
|
||||
}
|
||||
inline float Contact::GetFriction() const
|
||||
{
|
||||
KGE_ASSERT(contact_);
|
||||
return contact_->GetFriction();
|
||||
}
|
||||
inline void Contact::ResetFriction()
|
||||
{
|
||||
KGE_ASSERT(contact_);
|
||||
contact_->ResetFriction();
|
||||
}
|
||||
inline void Contact::SetRestitution(float restitution)
|
||||
{
|
||||
KGE_ASSERT(contact_);
|
||||
contact_->SetRestitution(restitution);
|
||||
}
|
||||
inline float Contact::GetRestitution() const
|
||||
{
|
||||
KGE_ASSERT(contact_);
|
||||
return contact_->GetRestitution();
|
||||
}
|
||||
inline void Contact::ResetRestitution()
|
||||
{
|
||||
KGE_ASSERT(contact_);
|
||||
contact_->ResetRestitution();
|
||||
}
|
||||
inline b2Contact* Contact::GetB2Contact() const
|
||||
{
|
||||
return contact_;
|
||||
}
|
||||
inline void Contact::SetB2Contact(b2Contact* contact)
|
||||
{
|
||||
contact_ = contact;
|
||||
}
|
||||
inline bool Contact::operator==(const Contact& rhs) const
|
||||
{
|
||||
return contact_ == rhs.contact_;
|
||||
}
|
||||
inline bool Contact::operator!=(const Contact& rhs) const
|
||||
{
|
||||
return contact_ != rhs.contact_;
|
||||
}
|
||||
|
||||
} // namespace physics
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -36,5 +36,5 @@ namespace kiwano
|
|||
SetB2ContactEdge(edge);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace physics
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -60,14 +60,12 @@ namespace kiwano
|
|||
b2ContactEdge* edge_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 物理接触边列表
|
||||
class ContactEdgeList
|
||||
{
|
||||
template <typename _Ty>
|
||||
class IteratorImpl
|
||||
: public std::iterator<std::forward_iterator_tag, _Ty>
|
||||
class IteratorImpl : public std::iterator<std::forward_iterator_tag, _Ty>
|
||||
{
|
||||
using herit = std::iterator<std::forward_iterator_tag, _Ty>;
|
||||
|
||||
|
|
@ -119,9 +117,7 @@ namespace kiwano
|
|||
using iterator = IteratorImpl<value_type>;
|
||||
using const_iterator = IteratorImpl<const value_type>;
|
||||
|
||||
inline ContactEdgeList()
|
||||
{
|
||||
}
|
||||
inline ContactEdgeList() {}
|
||||
|
||||
inline ContactEdgeList(const value_type& first)
|
||||
: first_(first)
|
||||
|
|
@ -174,13 +170,36 @@ namespace kiwano
|
|||
|
||||
/** @} */
|
||||
|
||||
inline bool ContactEdge::IsValid() const { return edge_ != nullptr; }
|
||||
inline Body* ContactEdge::GetOtherBody() const { KGE_ASSERT(edge_); return static_cast<Body*>(edge_->other->GetUserData()); }
|
||||
inline Contact ContactEdge::GetContact() const { KGE_ASSERT(edge_); return Contact(edge_->contact); }
|
||||
inline b2ContactEdge* ContactEdge::GetB2ContactEdge() const { return edge_; }
|
||||
inline void ContactEdge::SetB2ContactEdge(b2ContactEdge* edge) { edge_ = edge; }
|
||||
inline bool ContactEdge::operator==(const ContactEdge& rhs) const { return edge_ == rhs.edge_; }
|
||||
inline bool ContactEdge::operator!=(const ContactEdge& rhs) const { return edge_ != rhs.edge_; }
|
||||
inline bool ContactEdge::IsValid() const
|
||||
{
|
||||
return edge_ != nullptr;
|
||||
}
|
||||
inline Body* ContactEdge::GetOtherBody() const
|
||||
{
|
||||
KGE_ASSERT(edge_);
|
||||
return static_cast<Body*>(edge_->other->GetUserData());
|
||||
}
|
||||
inline Contact ContactEdge::GetContact() const
|
||||
{
|
||||
KGE_ASSERT(edge_);
|
||||
return Contact(edge_->contact);
|
||||
}
|
||||
inline b2ContactEdge* ContactEdge::GetB2ContactEdge() const
|
||||
{
|
||||
return edge_;
|
||||
}
|
||||
inline void ContactEdge::SetB2ContactEdge(b2ContactEdge* edge)
|
||||
{
|
||||
edge_ = edge;
|
||||
}
|
||||
inline bool ContactEdge::operator==(const ContactEdge& rhs) const
|
||||
{
|
||||
return edge_ == rhs.edge_;
|
||||
}
|
||||
inline bool ContactEdge::operator!=(const ContactEdge& rhs) const
|
||||
{
|
||||
return edge_ != rhs.edge_;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace physics
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -46,5 +46,5 @@ namespace kiwano
|
|||
this->contact = contact;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace physics
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano-physics/Contact.h>
|
||||
#include <kiwano-physics/Body.h>
|
||||
#include <kiwano-physics/Contact.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -36,8 +36,7 @@ namespace kiwano
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 物理接触开始事件
|
||||
class KGE_API ContactBeginEvent
|
||||
: public Event
|
||||
class KGE_API ContactBeginEvent : public Event
|
||||
{
|
||||
public:
|
||||
Contact contact; ///< 产生的接触
|
||||
|
|
@ -49,8 +48,7 @@ namespace kiwano
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 物理接触结束事件
|
||||
class KGE_API ContactEndEvent
|
||||
: public Event
|
||||
class KGE_API ContactEndEvent : public Event
|
||||
{
|
||||
public:
|
||||
Contact contact; ///< 产生的接触
|
||||
|
|
@ -61,5 +59,5 @@ namespace kiwano
|
|||
};
|
||||
|
||||
/** @} */
|
||||
}
|
||||
}
|
||||
} // namespace physics
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#include <kiwano-physics/Fixture.h>
|
||||
#include <kiwano-physics/Body.h>
|
||||
#include <kiwano-physics/Fixture.h>
|
||||
#include <kiwano-physics/World.h>
|
||||
|
||||
namespace kiwano
|
||||
|
|
@ -83,9 +83,12 @@ namespace kiwano
|
|||
b2MassData data;
|
||||
fixture_->GetMassData(&data);
|
||||
|
||||
if (mass) *mass = data.mass;
|
||||
if (center) *center = world->World2Stage(data.center);
|
||||
if (inertia) *inertia = data.I;
|
||||
if (mass)
|
||||
*mass = data.mass;
|
||||
if (center)
|
||||
*center = world->World2Stage(data.center);
|
||||
if (inertia)
|
||||
*inertia = data.I;
|
||||
}
|
||||
|
||||
bool Fixture::TestPoint(const Point& p) const
|
||||
|
|
@ -101,5 +104,5 @@ namespace kiwano
|
|||
return fixture_->TestPoint(world->Stage2World(p));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace physics
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano-physics/helper.h>
|
||||
#include <kiwano-physics/Shape.h>
|
||||
#include <kiwano-physics/helper.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -54,7 +54,8 @@ namespace kiwano
|
|||
, friction(friction)
|
||||
, restitution(restitution)
|
||||
, is_sensor(is_sensor)
|
||||
{}
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
Fixture();
|
||||
|
|
@ -126,12 +127,10 @@ namespace kiwano
|
|||
|
||||
/// \~chinese
|
||||
/// @brief ÎïÀí¼Ð¾ßÁбí
|
||||
class FixtureList
|
||||
: public List<Fixture>
|
||||
class FixtureList : public List<Fixture>
|
||||
{
|
||||
template <typename _Ty>
|
||||
class IteratorImpl
|
||||
: public std::iterator<std::forward_iterator_tag, _Ty>
|
||||
class IteratorImpl : public std::iterator<std::forward_iterator_tag, _Ty>
|
||||
{
|
||||
using herit = std::iterator<std::forward_iterator_tag, _Ty>;
|
||||
|
||||
|
|
@ -183,9 +182,7 @@ namespace kiwano
|
|||
using iterator = IteratorImpl<value_type>;
|
||||
using const_iterator = IteratorImpl<const value_type>;
|
||||
|
||||
inline FixtureList()
|
||||
{
|
||||
}
|
||||
inline FixtureList() {}
|
||||
|
||||
inline FixtureList(const value_type& first)
|
||||
: first_(first)
|
||||
|
|
@ -238,18 +235,65 @@ namespace kiwano
|
|||
|
||||
/** @} */
|
||||
|
||||
inline bool Fixture::IsSensor() const { KGE_ASSERT(fixture_); return fixture_->IsSensor(); }
|
||||
inline void Fixture::SetSensor(bool sensor) { KGE_ASSERT(fixture_); fixture_->SetSensor(sensor); }
|
||||
inline float Fixture::GetDensity() const { KGE_ASSERT(fixture_); return fixture_->GetDensity(); }
|
||||
inline void Fixture::SetDensity(float density) { KGE_ASSERT(fixture_); fixture_->SetDensity(density); }
|
||||
inline float Fixture::GetFriction() const { KGE_ASSERT(fixture_); return fixture_->GetFriction(); }
|
||||
inline void Fixture::SetFriction(float friction) { KGE_ASSERT(fixture_); fixture_->SetFriction(friction); }
|
||||
inline float Fixture::GetRestitution() const { KGE_ASSERT(fixture_); return fixture_->GetRestitution(); }
|
||||
inline void Fixture::SetRestitution(float restitution) { KGE_ASSERT(fixture_); fixture_->SetRestitution(restitution); }
|
||||
inline bool Fixture::IsValid() const { return fixture_ != nullptr; }
|
||||
inline b2Fixture* Fixture::GetB2Fixture() const { return fixture_; }
|
||||
inline void Fixture::SetB2Fixture(b2Fixture* fixture) { fixture_ = fixture; }
|
||||
inline bool Fixture::operator==(const Fixture& rhs) const { return fixture_ == rhs.fixture_; }
|
||||
inline bool Fixture::operator!=(const Fixture& rhs) const { return fixture_ != rhs.fixture_; }
|
||||
inline bool Fixture::IsSensor() const
|
||||
{
|
||||
KGE_ASSERT(fixture_);
|
||||
return fixture_->IsSensor();
|
||||
}
|
||||
inline void Fixture::SetSensor(bool sensor)
|
||||
{
|
||||
KGE_ASSERT(fixture_);
|
||||
fixture_->SetSensor(sensor);
|
||||
}
|
||||
inline float Fixture::GetDensity() const
|
||||
{
|
||||
KGE_ASSERT(fixture_);
|
||||
return fixture_->GetDensity();
|
||||
}
|
||||
inline void Fixture::SetDensity(float density)
|
||||
{
|
||||
KGE_ASSERT(fixture_);
|
||||
fixture_->SetDensity(density);
|
||||
}
|
||||
inline float Fixture::GetFriction() const
|
||||
{
|
||||
KGE_ASSERT(fixture_);
|
||||
return fixture_->GetFriction();
|
||||
}
|
||||
inline void Fixture::SetFriction(float friction)
|
||||
{
|
||||
KGE_ASSERT(fixture_);
|
||||
fixture_->SetFriction(friction);
|
||||
}
|
||||
inline float Fixture::GetRestitution() const
|
||||
{
|
||||
KGE_ASSERT(fixture_);
|
||||
return fixture_->GetRestitution();
|
||||
}
|
||||
inline void Fixture::SetRestitution(float restitution)
|
||||
{
|
||||
KGE_ASSERT(fixture_);
|
||||
fixture_->SetRestitution(restitution);
|
||||
}
|
||||
inline bool Fixture::IsValid() const
|
||||
{
|
||||
return fixture_ != nullptr;
|
||||
}
|
||||
inline b2Fixture* Fixture::GetB2Fixture() const
|
||||
{
|
||||
return fixture_;
|
||||
}
|
||||
inline void Fixture::SetB2Fixture(b2Fixture* fixture)
|
||||
{
|
||||
fixture_ = fixture;
|
||||
}
|
||||
inline bool Fixture::operator==(const Fixture& rhs) const
|
||||
{
|
||||
return fixture_ == rhs.fixture_;
|
||||
}
|
||||
inline bool Fixture::operator!=(const Fixture& rhs) const
|
||||
{
|
||||
return fixture_ != rhs.fixture_;
|
||||
}
|
||||
} // namespace physics
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -108,7 +108,8 @@ namespace kiwano
|
|||
KGE_ASSERT(param.body_a && param.body_b);
|
||||
|
||||
b2DistanceJointDef def;
|
||||
def.Initialize(param.body_a->GetB2Body(), param.body_b->GetB2Body(), world->Stage2World(param.anchor_a), world->Stage2World(param.anchor_b));
|
||||
def.Initialize(param.body_a->GetB2Body(), param.body_b->GetB2Body(), world->Stage2World(param.anchor_a),
|
||||
world->Stage2World(param.anchor_b));
|
||||
def.frequencyHz = param.frequency_hz;
|
||||
def.dampingRatio = param.damping_ratio;
|
||||
|
||||
|
|
@ -277,7 +278,8 @@ namespace kiwano
|
|||
KGE_ASSERT(param.body_a && param.body_b);
|
||||
|
||||
b2PrismaticJointDef def;
|
||||
def.Initialize(param.body_a->GetB2Body(), param.body_b->GetB2Body(), world->Stage2World(param.anchor), Stage2World(param.axis));
|
||||
def.Initialize(param.body_a->GetB2Body(), param.body_b->GetB2Body(), world->Stage2World(param.anchor),
|
||||
Stage2World(param.axis));
|
||||
def.enableLimit = param.enable_limit;
|
||||
def.lowerTranslation = world->Stage2World(param.lower_translation);
|
||||
def.upperTranslation = world->Stage2World(param.upper_translation);
|
||||
|
|
@ -335,8 +337,9 @@ namespace kiwano
|
|||
KGE_ASSERT(param.body_a && param.body_b);
|
||||
|
||||
b2PulleyJointDef def;
|
||||
def.Initialize(param.body_a->GetB2Body(), param.body_b->GetB2Body(), world->Stage2World(param.ground_anchor_a), world->Stage2World(param.ground_anchor_b),
|
||||
world->Stage2World(param.anchor_a), world->Stage2World(param.anchor_b), param.ratio);
|
||||
def.Initialize(param.body_a->GetB2Body(), param.body_b->GetB2Body(), world->Stage2World(param.ground_anchor_a),
|
||||
world->Stage2World(param.ground_anchor_b), world->Stage2World(param.anchor_a),
|
||||
world->Stage2World(param.anchor_b), param.ratio);
|
||||
|
||||
Joint::InitJoint(world, &def);
|
||||
raw_joint_ = static_cast<b2PulleyJoint*>(GetB2Joint());
|
||||
|
|
@ -517,7 +520,6 @@ namespace kiwano
|
|||
return raw_joint_ != nullptr;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// WheelJoint
|
||||
//
|
||||
|
|
@ -533,7 +535,8 @@ namespace kiwano
|
|||
KGE_ASSERT(param.body_a && param.body_b);
|
||||
|
||||
b2WheelJointDef def;
|
||||
def.Initialize(param.body_a->GetB2Body(), param.body_b->GetB2Body(), world->Stage2World(param.anchor), Stage2World(param.axis));
|
||||
def.Initialize(param.body_a->GetB2Body(), param.body_b->GetB2Body(), world->Stage2World(param.anchor),
|
||||
Stage2World(param.axis));
|
||||
def.enableMotor = param.enable_motor;
|
||||
def.maxMotorTorque = world->Stage2World(param.max_motor_torque);
|
||||
def.motorSpeed = world->Stage2World(param.motor_speed);
|
||||
|
|
@ -608,5 +611,5 @@ namespace kiwano
|
|||
return raw_joint_->GetMaxForce();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace physics
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano-physics/helper.h>
|
||||
#include <kiwano-physics/Body.h>
|
||||
#include <kiwano-physics/helper.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -46,8 +46,7 @@ namespace kiwano
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 关节
|
||||
class KGE_API Joint
|
||||
: public virtual ObjectBase
|
||||
class KGE_API Joint : public virtual ObjectBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -76,12 +75,14 @@ namespace kiwano
|
|||
Body* body_b; ///< 关节连接的物体B
|
||||
|
||||
ParamBase(Body* body_a, Body* body_b)
|
||||
: body_a(body_a), body_b(body_b)
|
||||
: body_a(body_a)
|
||||
, body_b(body_b)
|
||||
{
|
||||
}
|
||||
|
||||
ParamBase(BodyPtr body_a, BodyPtr body_b)
|
||||
: body_a(body_a.get()), body_b(body_b.get())
|
||||
: body_a(body_a.get())
|
||||
, body_b(body_b.get())
|
||||
{
|
||||
}
|
||||
};
|
||||
|
|
@ -119,11 +120,9 @@ namespace kiwano
|
|||
Type type_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 固定距离关节
|
||||
class KGE_API DistanceJoint
|
||||
: public Joint
|
||||
class KGE_API DistanceJoint : public Joint
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -135,31 +134,21 @@ namespace kiwano
|
|||
float frequency_hz; ///< 响应速度,数值越高关节响应的速度越快,看上去越坚固
|
||||
float damping_ratio; ///< 阻尼率,值越大关节运动阻尼越大
|
||||
|
||||
Param(
|
||||
Body* body_a,
|
||||
Body* body_b,
|
||||
Point const& anchor_a,
|
||||
Point const& anchor_b,
|
||||
float frequency_hz = 0.f,
|
||||
float damping_ratio = 0.f
|
||||
)
|
||||
Param(Body* body_a, Body* body_b, Point const& anchor_a, Point const& anchor_b, float frequency_hz = 0.f,
|
||||
float damping_ratio = 0.f)
|
||||
: ParamBase(body_a, body_b)
|
||||
, anchor_a(anchor_a)
|
||||
, anchor_b(anchor_b)
|
||||
, frequency_hz(frequency_hz)
|
||||
, damping_ratio(damping_ratio)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
Param(
|
||||
BodyPtr body_a,
|
||||
BodyPtr body_b,
|
||||
Point const& anchor_a,
|
||||
Point const& anchor_b,
|
||||
float frequency_hz = 0.f,
|
||||
float damping_ratio = 0.f
|
||||
)
|
||||
Param(BodyPtr body_a, BodyPtr body_b, Point const& anchor_a, Point const& anchor_b, float frequency_hz = 0.f,
|
||||
float damping_ratio = 0.f)
|
||||
: Param(body_a.get(), body_b.get(), anchor_a, anchor_b, frequency_hz, damping_ratio)
|
||||
{}
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
DistanceJoint();
|
||||
|
|
@ -196,11 +185,9 @@ namespace kiwano
|
|||
b2DistanceJoint* raw_joint_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 摩擦关节
|
||||
class KGE_API FrictionJoint
|
||||
: public Joint
|
||||
class KGE_API FrictionJoint : public Joint
|
||||
{
|
||||
public:
|
||||
struct Param : public Joint::ParamBase
|
||||
|
|
@ -209,28 +196,18 @@ namespace kiwano
|
|||
float max_force; ///< 最大摩擦力
|
||||
float max_torque; ///< 最大扭力
|
||||
|
||||
Param(
|
||||
Body* body_a,
|
||||
Body* body_b,
|
||||
Point const& anchor,
|
||||
float max_force = 0.f,
|
||||
float max_torque = 0.f
|
||||
)
|
||||
Param(Body* body_a, Body* body_b, Point const& anchor, float max_force = 0.f, float max_torque = 0.f)
|
||||
: ParamBase(body_a, body_b)
|
||||
, anchor(anchor)
|
||||
, max_force(max_force)
|
||||
, max_torque(max_torque)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
Param(
|
||||
BodyPtr body_a,
|
||||
BodyPtr body_b,
|
||||
Point const& anchor,
|
||||
float max_force = 0.f,
|
||||
float max_torque = 0.f
|
||||
)
|
||||
Param(BodyPtr body_a, BodyPtr body_b, Point const& anchor, float max_force = 0.f, float max_torque = 0.f)
|
||||
: Param(body_a.get(), body_b.get(), anchor, max_force, max_torque)
|
||||
{}
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
FrictionJoint();
|
||||
|
|
@ -259,11 +236,9 @@ namespace kiwano
|
|||
b2FrictionJoint* raw_joint_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 齿轮关节
|
||||
class KGE_API GearJoint
|
||||
: public Joint
|
||||
class KGE_API GearJoint : public Joint
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -274,24 +249,18 @@ namespace kiwano
|
|||
Joint* joint_b; ///< 关节B(旋转关节/平移关节)
|
||||
float ratio; ///< 齿轮传动比
|
||||
|
||||
Param(
|
||||
Joint* joint_a,
|
||||
Joint* joint_b,
|
||||
float ratio = 1.f
|
||||
)
|
||||
Param(Joint* joint_a, Joint* joint_b, float ratio = 1.f)
|
||||
: ParamBase(nullptr, nullptr)
|
||||
, joint_a(joint_a)
|
||||
, joint_b(joint_b)
|
||||
, ratio(ratio)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
Param(
|
||||
JointPtr joint_a,
|
||||
JointPtr joint_b,
|
||||
float ratio = 1.f
|
||||
)
|
||||
Param(JointPtr joint_a, JointPtr joint_b, float ratio = 1.f)
|
||||
: Param(joint_a.get(), joint_b.get(), ratio)
|
||||
{}
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
GearJoint();
|
||||
|
|
@ -312,11 +281,9 @@ namespace kiwano
|
|||
b2GearJoint* raw_joint_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 马达关节
|
||||
class KGE_API MotorJoint
|
||||
: public Joint
|
||||
class KGE_API MotorJoint : public Joint
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -327,28 +294,20 @@ namespace kiwano
|
|||
float max_torque; ///< 最大转矩
|
||||
float correction_factor; ///< 位置矫正因子(范围 0-1)
|
||||
|
||||
Param(
|
||||
Body* body_a,
|
||||
Body* body_b,
|
||||
float max_force = 1.f,
|
||||
float max_torque = 100.f,
|
||||
float correction_factor = 0.3f
|
||||
)
|
||||
Param(Body* body_a, Body* body_b, float max_force = 1.f, float max_torque = 100.f,
|
||||
float correction_factor = 0.3f)
|
||||
: ParamBase(body_a, body_b)
|
||||
, max_force(max_force)
|
||||
, max_torque(max_torque)
|
||||
, correction_factor(correction_factor)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
Param(
|
||||
BodyPtr body_a,
|
||||
BodyPtr body_b,
|
||||
float max_force = 0.f,
|
||||
float max_torque = 0.f,
|
||||
float correction_factor = 0.3f
|
||||
)
|
||||
Param(BodyPtr body_a, BodyPtr body_b, float max_force = 0.f, float max_torque = 0.f,
|
||||
float correction_factor = 0.3f)
|
||||
: Param(body_a.get(), body_b.get(), max_force, max_torque, correction_factor)
|
||||
{}
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
MotorJoint();
|
||||
|
|
@ -377,11 +336,9 @@ namespace kiwano
|
|||
b2MotorJoint* raw_joint_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 平移关节
|
||||
class KGE_API PrismaticJoint
|
||||
: public Joint
|
||||
class KGE_API PrismaticJoint : public Joint
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -397,18 +354,9 @@ namespace kiwano
|
|||
float max_motor_force; ///< 最大马达力 [N]
|
||||
float motor_speed; ///< 马达转速 [degree/s]
|
||||
|
||||
Param(
|
||||
Body* body_a,
|
||||
Body* body_b,
|
||||
Point const& anchor,
|
||||
Vec2 const& axis,
|
||||
bool enable_limit = false,
|
||||
float lower_translation = 0.0f,
|
||||
float upper_translation = 0.0f,
|
||||
bool enable_motor = false,
|
||||
float max_motor_force = 0.0f,
|
||||
float motor_speed = 0.0f
|
||||
)
|
||||
Param(Body* body_a, Body* body_b, Point const& anchor, Vec2 const& axis, bool enable_limit = false,
|
||||
float lower_translation = 0.0f, float upper_translation = 0.0f, bool enable_motor = false,
|
||||
float max_motor_force = 0.0f, float motor_speed = 0.0f)
|
||||
: ParamBase(body_a, body_b)
|
||||
, anchor(anchor)
|
||||
, axis(axis)
|
||||
|
|
@ -418,22 +366,16 @@ namespace kiwano
|
|||
, enable_motor(enable_motor)
|
||||
, max_motor_force(max_motor_force)
|
||||
, motor_speed(motor_speed)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
Param(
|
||||
BodyPtr body_a,
|
||||
BodyPtr body_b,
|
||||
Point const& anchor,
|
||||
Vec2 const& axis,
|
||||
bool enable_limit = false,
|
||||
float lower_translation = 0.0f,
|
||||
float upper_translation = 0.0f,
|
||||
bool enable_motor = false,
|
||||
float max_motor_force = 0.0f,
|
||||
float motor_speed = 0.0f
|
||||
)
|
||||
: Param(body_a.get(), body_b.get(), anchor, axis, enable_limit, lower_translation, upper_translation, enable_motor, max_motor_force, motor_speed)
|
||||
{}
|
||||
Param(BodyPtr body_a, BodyPtr body_b, Point const& anchor, Vec2 const& axis, bool enable_limit = false,
|
||||
float lower_translation = 0.0f, float upper_translation = 0.0f, bool enable_motor = false,
|
||||
float max_motor_force = 0.0f, float motor_speed = 0.0f)
|
||||
: Param(body_a.get(), body_b.get(), anchor, axis, enable_limit, lower_translation, upper_translation,
|
||||
enable_motor, max_motor_force, motor_speed)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
PrismaticJoint();
|
||||
|
|
@ -502,11 +444,9 @@ namespace kiwano
|
|||
b2PrismaticJoint* raw_joint_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 滑轮关节
|
||||
class KGE_API PulleyJoint
|
||||
: public Joint
|
||||
class KGE_API PulleyJoint : public Joint
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -519,34 +459,22 @@ namespace kiwano
|
|||
Point ground_anchor_b; ///< 物体B对应的滑轮的位置
|
||||
float ratio; ///< 滑轮比,关节传动时,滑轮上升和下降的两头的位移比例
|
||||
|
||||
Param(
|
||||
Body* body_a,
|
||||
Body* body_b,
|
||||
Point const& anchor_a,
|
||||
Point const& anchor_b,
|
||||
Point const& ground_anchor_a,
|
||||
Point const& ground_anchor_b,
|
||||
float ratio = 1.0f
|
||||
)
|
||||
Param(Body* body_a, Body* body_b, Point const& anchor_a, Point const& anchor_b, Point const& ground_anchor_a,
|
||||
Point const& ground_anchor_b, float ratio = 1.0f)
|
||||
: ParamBase(body_a, body_b)
|
||||
, anchor_a(anchor_a)
|
||||
, anchor_b(anchor_b)
|
||||
, ground_anchor_a(ground_anchor_a)
|
||||
, ground_anchor_b(ground_anchor_b)
|
||||
, ratio(ratio)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
Param(
|
||||
BodyPtr body_a,
|
||||
BodyPtr body_b,
|
||||
Point const& anchor_a,
|
||||
Point const& anchor_b,
|
||||
Point const& ground_anchor_a,
|
||||
Point const& ground_anchor_b,
|
||||
float ratio = 1.0f
|
||||
)
|
||||
Param(BodyPtr body_a, BodyPtr body_b, Point const& anchor_a, Point const& anchor_b,
|
||||
Point const& ground_anchor_a, Point const& ground_anchor_b, float ratio = 1.0f)
|
||||
: Param(body_a.get(), body_b.get(), anchor_a, anchor_b, ground_anchor_a, ground_anchor_b, ratio)
|
||||
{}
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
PulleyJoint();
|
||||
|
|
@ -587,11 +515,9 @@ namespace kiwano
|
|||
b2PulleyJoint* raw_joint_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 旋转关节
|
||||
class KGE_API RevoluteJoint
|
||||
: public Joint
|
||||
class KGE_API RevoluteJoint : public Joint
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -606,17 +532,9 @@ namespace kiwano
|
|||
float max_motor_torque; ///< 最大马达力 [N]
|
||||
float motor_speed; ///< 马达转速 [degree/s]
|
||||
|
||||
Param(
|
||||
Body* body_a,
|
||||
Body* body_b,
|
||||
Point const& anchor,
|
||||
bool enable_limit = false,
|
||||
float lower_angle = 0.0f,
|
||||
float upper_angle = 0.0f,
|
||||
bool enable_motor = false,
|
||||
float max_motor_torque = 0.0f,
|
||||
float motor_speed = 0.0f
|
||||
)
|
||||
Param(Body* body_a, Body* body_b, Point const& anchor, bool enable_limit = false, float lower_angle = 0.0f,
|
||||
float upper_angle = 0.0f, bool enable_motor = false, float max_motor_torque = 0.0f,
|
||||
float motor_speed = 0.0f)
|
||||
: ParamBase(body_a, body_b)
|
||||
, anchor(anchor)
|
||||
, enable_limit(enable_limit)
|
||||
|
|
@ -625,21 +543,16 @@ namespace kiwano
|
|||
, enable_motor(enable_motor)
|
||||
, max_motor_torque(max_motor_torque)
|
||||
, motor_speed(motor_speed)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
Param(
|
||||
BodyPtr body_a,
|
||||
BodyPtr body_b,
|
||||
Point const& anchor,
|
||||
bool enable_limit = false,
|
||||
float lower_angle = 0.0f,
|
||||
float upper_angle = 0.0f,
|
||||
bool enable_motor = false,
|
||||
float max_motor_torque = 0.0f,
|
||||
float motor_speed = 0.0f
|
||||
)
|
||||
: Param(body_a.get(), body_b.get(), anchor, enable_limit, lower_angle, upper_angle, enable_motor, max_motor_torque, motor_speed)
|
||||
{}
|
||||
Param(BodyPtr body_a, BodyPtr body_b, Point const& anchor, bool enable_limit = false, float lower_angle = 0.0f,
|
||||
float upper_angle = 0.0f, bool enable_motor = false, float max_motor_torque = 0.0f,
|
||||
float motor_speed = 0.0f)
|
||||
: Param(body_a.get(), body_b.get(), anchor, enable_limit, lower_angle, upper_angle, enable_motor,
|
||||
max_motor_torque, motor_speed)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
RevoluteJoint();
|
||||
|
|
@ -708,11 +621,9 @@ namespace kiwano
|
|||
b2RevoluteJoint* raw_joint_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 绳关节
|
||||
class KGE_API RopeJoint
|
||||
: public Joint
|
||||
class KGE_API RopeJoint : public Joint
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -723,28 +634,20 @@ namespace kiwano
|
|||
Point local_anchor_b; ///< 关节在物体B上的连接点
|
||||
float max_length; ///< 绳索最大长度
|
||||
|
||||
Param(
|
||||
Body* body_a,
|
||||
Body* body_b,
|
||||
Point const& local_anchor_a,
|
||||
Point const& local_anchor_b,
|
||||
float max_length = 0.f
|
||||
)
|
||||
Param(Body* body_a, Body* body_b, Point const& local_anchor_a, Point const& local_anchor_b,
|
||||
float max_length = 0.f)
|
||||
: ParamBase(body_a, body_b)
|
||||
, local_anchor_a(local_anchor_a)
|
||||
, local_anchor_b(local_anchor_b)
|
||||
, max_length(max_length)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
Param(
|
||||
BodyPtr body_a,
|
||||
BodyPtr body_b,
|
||||
Point const& local_anchor_a,
|
||||
Point const& local_anchor_b,
|
||||
float max_length = 0.f
|
||||
)
|
||||
Param(BodyPtr body_a, BodyPtr body_b, Point const& local_anchor_a, Point const& local_anchor_b,
|
||||
float max_length = 0.f)
|
||||
: Param(body_a.get(), body_b.get(), local_anchor_a, local_anchor_b, max_length)
|
||||
{}
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
RopeJoint();
|
||||
|
|
@ -765,11 +668,9 @@ namespace kiwano
|
|||
b2RopeJoint* raw_joint_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 焊接关节
|
||||
class KGE_API WeldJoint
|
||||
: public Joint
|
||||
class KGE_API WeldJoint : public Joint
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -780,28 +681,18 @@ namespace kiwano
|
|||
float frequency_hz; ///< 响应速度,数值越高关节响应的速度越快,看上去越坚固
|
||||
float damping_ratio; ///< 阻尼率,值越大关节运动阻尼越大
|
||||
|
||||
Param(
|
||||
Body* body_a,
|
||||
Body* body_b,
|
||||
Point const& anchor,
|
||||
float frequency_hz = 0.f,
|
||||
float damping_ratio = 0.f
|
||||
)
|
||||
Param(Body* body_a, Body* body_b, Point const& anchor, float frequency_hz = 0.f, float damping_ratio = 0.f)
|
||||
: ParamBase(body_a, body_b)
|
||||
, anchor(anchor)
|
||||
, frequency_hz(frequency_hz)
|
||||
, damping_ratio(damping_ratio)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
Param(
|
||||
BodyPtr body_a,
|
||||
BodyPtr body_b,
|
||||
Point const& anchor,
|
||||
float frequency_hz = 0.f,
|
||||
float damping_ratio = 0.f
|
||||
)
|
||||
Param(BodyPtr body_a, BodyPtr body_b, Point const& anchor, float frequency_hz = 0.f, float damping_ratio = 0.f)
|
||||
: Param(body_a.get(), body_b.get(), anchor, frequency_hz, damping_ratio)
|
||||
{}
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
WeldJoint();
|
||||
|
|
@ -834,11 +725,9 @@ namespace kiwano
|
|||
b2WeldJoint* raw_joint_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 轮关节
|
||||
class KGE_API WheelJoint
|
||||
: public Joint
|
||||
class KGE_API WheelJoint : public Joint
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -853,17 +742,9 @@ namespace kiwano
|
|||
float frequency_hz; ///< 响应速度,数值越高关节响应的速度越快,看上去越坚固
|
||||
float damping_ratio; ///< 弹簧阻尼率,值越大关节运动阻尼越大
|
||||
|
||||
Param(
|
||||
Body* body_a,
|
||||
Body* body_b,
|
||||
Point const& anchor,
|
||||
Vec2 const& axis,
|
||||
float frequency_hz = 2.0f,
|
||||
float damping_ratio = 0.7f,
|
||||
bool enable_motor = false,
|
||||
float max_motor_torque = 0.0f,
|
||||
float motor_speed = 0.0f
|
||||
)
|
||||
Param(Body* body_a, Body* body_b, Point const& anchor, Vec2 const& axis, float frequency_hz = 2.0f,
|
||||
float damping_ratio = 0.7f, bool enable_motor = false, float max_motor_torque = 0.0f,
|
||||
float motor_speed = 0.0f)
|
||||
: ParamBase(body_a, body_b)
|
||||
, anchor(anchor)
|
||||
, axis(axis)
|
||||
|
|
@ -872,21 +753,16 @@ namespace kiwano
|
|||
, motor_speed(motor_speed)
|
||||
, frequency_hz(frequency_hz)
|
||||
, damping_ratio(damping_ratio)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
Param(
|
||||
BodyPtr body_a,
|
||||
BodyPtr body_b,
|
||||
Point const& anchor,
|
||||
Vec2 const& axis,
|
||||
float frequency_hz = 2.0f,
|
||||
float damping_ratio = 0.7f,
|
||||
bool enable_motor = false,
|
||||
float max_motor_torque = 0.0f,
|
||||
float motor_speed = 0.0f
|
||||
)
|
||||
: Param(body_a.get(), body_b.get(), anchor, axis, frequency_hz, damping_ratio, enable_motor, max_motor_torque, motor_speed)
|
||||
{}
|
||||
Param(BodyPtr body_a, BodyPtr body_b, Point const& anchor, Vec2 const& axis, float frequency_hz = 2.0f,
|
||||
float damping_ratio = 0.7f, bool enable_motor = false, float max_motor_torque = 0.0f,
|
||||
float motor_speed = 0.0f)
|
||||
: Param(body_a.get(), body_b.get(), anchor, axis, frequency_hz, damping_ratio, enable_motor,
|
||||
max_motor_torque, motor_speed)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
WheelJoint();
|
||||
|
|
@ -955,12 +831,10 @@ namespace kiwano
|
|||
b2WheelJoint* raw_joint_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 鼠标关节
|
||||
/// @details 用于使身体的某个点追踪世界上的指定点,例如让物体追踪鼠标位置
|
||||
class KGE_API MouseJoint
|
||||
: public Joint
|
||||
class KGE_API MouseJoint : public Joint
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -972,24 +846,21 @@ namespace kiwano
|
|||
float frequency_hz; ///< 响应速度,数值越高关节响应的速度越快,看上去越坚固
|
||||
float damping_ratio; ///< 阻尼率,值越大关节运动阻尼越大
|
||||
|
||||
Param(
|
||||
Body* body_a,
|
||||
Body* body_b,
|
||||
Point const& target,
|
||||
float max_force,
|
||||
float frequency_hz = 5.0f,
|
||||
float damping_ratio = 0.7f
|
||||
)
|
||||
Param(Body* body_a, Body* body_b, Point const& target, float max_force, float frequency_hz = 5.0f,
|
||||
float damping_ratio = 0.7f)
|
||||
: ParamBase(body_a, body_b)
|
||||
, target(target)
|
||||
, max_force(max_force)
|
||||
, frequency_hz(frequency_hz)
|
||||
, damping_ratio(damping_ratio)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
Param(BodyPtr body_a, BodyPtr body_b, Point const& target, float max_force, float frequency_hz = 5.0f, float damping_ratio = 0.7f)
|
||||
Param(BodyPtr body_a, BodyPtr body_b, Point const& target, float max_force, float frequency_hz = 5.0f,
|
||||
float damping_ratio = 0.7f)
|
||||
: Param(body_a.get(), body_b.get(), target, max_force, frequency_hz, damping_ratio)
|
||||
{}
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
MouseJoint();
|
||||
|
|
@ -1028,53 +899,214 @@ namespace kiwano
|
|||
|
||||
/** @} */
|
||||
|
||||
|
||||
inline b2Joint* Joint::GetB2Joint() const { return joint_; }
|
||||
inline World* Joint::GetWorld() const { return world_; }
|
||||
|
||||
inline void DistanceJoint::SetFrequency(float hz) { KGE_ASSERT(raw_joint_); raw_joint_->SetFrequency(hz); }
|
||||
inline float DistanceJoint::GetFrequency() const { KGE_ASSERT(raw_joint_); return raw_joint_->GetFrequency(); }
|
||||
inline void DistanceJoint::SetDampingRatio(float ratio) { KGE_ASSERT(raw_joint_); raw_joint_->SetDampingRatio(ratio); }
|
||||
inline float DistanceJoint::GetDampingRatio() const { KGE_ASSERT(raw_joint_); return raw_joint_->GetDampingRatio(); }
|
||||
|
||||
inline float PrismaticJoint::GetReferenceAngle() const { KGE_ASSERT(raw_joint_); return math::Radian2Degree(raw_joint_->GetReferenceAngle()); }
|
||||
inline bool PrismaticJoint::IsLimitEnabled() const { KGE_ASSERT(raw_joint_); return raw_joint_->IsLimitEnabled(); }
|
||||
inline void PrismaticJoint::EnableLimit(bool flag) { KGE_ASSERT(raw_joint_); raw_joint_->EnableLimit(flag); }
|
||||
inline bool PrismaticJoint::IsMotorEnabled() const { KGE_ASSERT(raw_joint_); return raw_joint_->IsMotorEnabled(); }
|
||||
inline void PrismaticJoint::EnableMotor(bool flag) { KGE_ASSERT(raw_joint_); raw_joint_->EnableMotor(flag); }
|
||||
inline void PrismaticJoint::SetMotorSpeed(float speed) { KGE_ASSERT(raw_joint_); raw_joint_->SetMotorSpeed(math::Degree2Radian(speed)); }
|
||||
inline float PrismaticJoint::GetMotorSpeed() const { KGE_ASSERT(raw_joint_); return math::Radian2Degree(raw_joint_->GetMotorSpeed()); }
|
||||
inline void PrismaticJoint::SetMaxMotorForce(float force) { KGE_ASSERT(raw_joint_); raw_joint_->SetMaxMotorForce(force); }
|
||||
inline float PrismaticJoint::GetMaxMotorForce() const { KGE_ASSERT(raw_joint_); return raw_joint_->GetMaxMotorForce(); }
|
||||
|
||||
inline float RevoluteJoint::GetReferenceAngle() const { KGE_ASSERT(raw_joint_); return math::Radian2Degree(raw_joint_->GetReferenceAngle()); }
|
||||
inline bool RevoluteJoint::IsLimitEnabled() const { KGE_ASSERT(raw_joint_); return raw_joint_->IsLimitEnabled(); }
|
||||
inline void RevoluteJoint::EnableLimit(bool flag) { KGE_ASSERT(raw_joint_); raw_joint_->EnableLimit(flag); }
|
||||
inline bool RevoluteJoint::IsMotorEnabled() const { KGE_ASSERT(raw_joint_); return raw_joint_->IsMotorEnabled(); }
|
||||
inline void RevoluteJoint::EnableMotor(bool flag) { KGE_ASSERT(raw_joint_); raw_joint_->EnableMotor(flag); }
|
||||
inline void RevoluteJoint::SetMotorSpeed(float speed) { KGE_ASSERT(raw_joint_); raw_joint_->SetMotorSpeed(math::Degree2Radian(speed)); }
|
||||
inline float RevoluteJoint::GetMotorSpeed() const { KGE_ASSERT(raw_joint_); return math::Radian2Degree(raw_joint_->GetMotorSpeed()); }
|
||||
|
||||
inline float WeldJoint::GetReferenceAngle() const { KGE_ASSERT(raw_joint_); return math::Radian2Degree(raw_joint_->GetReferenceAngle()); }
|
||||
inline void WeldJoint::SetFrequency(float hz) { KGE_ASSERT(raw_joint_); raw_joint_->SetFrequency(hz); }
|
||||
inline float WeldJoint::GetFrequency() const { KGE_ASSERT(raw_joint_); return raw_joint_->GetFrequency(); }
|
||||
inline void WeldJoint::SetDampingRatio(float ratio) { KGE_ASSERT(raw_joint_); raw_joint_->SetDampingRatio(ratio); }
|
||||
inline float WeldJoint::GetDampingRatio() const { KGE_ASSERT(raw_joint_); return raw_joint_->GetDampingRatio(); }
|
||||
|
||||
inline float WheelJoint::GetJointAngle() const { KGE_ASSERT(raw_joint_); return math::Radian2Degree(raw_joint_->GetJointAngle()); }
|
||||
inline float WheelJoint::GetJointAngularSpeed() const { KGE_ASSERT(raw_joint_); return math::Radian2Degree(raw_joint_->GetJointAngularSpeed()); }
|
||||
inline bool WheelJoint::IsMotorEnabled() const { KGE_ASSERT(raw_joint_); return raw_joint_->IsMotorEnabled(); }
|
||||
inline void WheelJoint::EnableMotor(bool flag) { KGE_ASSERT(raw_joint_); raw_joint_->EnableMotor(flag); }
|
||||
inline void WheelJoint::SetMotorSpeed(float speed) { KGE_ASSERT(raw_joint_); raw_joint_->SetMotorSpeed(math::Degree2Radian(speed)); }
|
||||
inline float WheelJoint::GetMotorSpeed() const { KGE_ASSERT(raw_joint_); return math::Radian2Degree(raw_joint_->GetMotorSpeed()); }
|
||||
inline void WheelJoint::SetSpringFrequencyHz(float hz) { KGE_ASSERT(raw_joint_); raw_joint_->SetSpringFrequencyHz(hz); }
|
||||
inline float WheelJoint::GetSpringFrequencyHz() const { KGE_ASSERT(raw_joint_); return raw_joint_->GetSpringFrequencyHz(); }
|
||||
inline void WheelJoint::SetSpringDampingRatio(float ratio) { KGE_ASSERT(raw_joint_); raw_joint_->SetSpringDampingRatio(ratio); }
|
||||
inline float WheelJoint::GetSpringDampingRatio() const { KGE_ASSERT(raw_joint_); return raw_joint_->GetSpringDampingRatio(); }
|
||||
|
||||
inline void MouseJoint::SetFrequency(float hz) { KGE_ASSERT(raw_joint_); raw_joint_->SetFrequency(hz); }
|
||||
inline float MouseJoint::GetFrequency() const { KGE_ASSERT(raw_joint_); return raw_joint_->GetFrequency(); }
|
||||
inline void MouseJoint::SetDampingRatio(float ratio) { KGE_ASSERT(raw_joint_); raw_joint_->SetDampingRatio(ratio); }
|
||||
inline float MouseJoint::GetDampingRatio() const { KGE_ASSERT(raw_joint_); return raw_joint_->GetDampingRatio(); }
|
||||
inline b2Joint* Joint::GetB2Joint() const
|
||||
{
|
||||
return joint_;
|
||||
}
|
||||
inline World* Joint::GetWorld() const
|
||||
{
|
||||
return world_;
|
||||
}
|
||||
|
||||
inline void DistanceJoint::SetFrequency(float hz)
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
raw_joint_->SetFrequency(hz);
|
||||
}
|
||||
inline float DistanceJoint::GetFrequency() const
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
return raw_joint_->GetFrequency();
|
||||
}
|
||||
inline void DistanceJoint::SetDampingRatio(float ratio)
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
raw_joint_->SetDampingRatio(ratio);
|
||||
}
|
||||
inline float DistanceJoint::GetDampingRatio() const
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
return raw_joint_->GetDampingRatio();
|
||||
}
|
||||
|
||||
inline float PrismaticJoint::GetReferenceAngle() const
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
return math::Radian2Degree(raw_joint_->GetReferenceAngle());
|
||||
}
|
||||
inline bool PrismaticJoint::IsLimitEnabled() const
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
return raw_joint_->IsLimitEnabled();
|
||||
}
|
||||
inline void PrismaticJoint::EnableLimit(bool flag)
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
raw_joint_->EnableLimit(flag);
|
||||
}
|
||||
inline bool PrismaticJoint::IsMotorEnabled() const
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
return raw_joint_->IsMotorEnabled();
|
||||
}
|
||||
inline void PrismaticJoint::EnableMotor(bool flag)
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
raw_joint_->EnableMotor(flag);
|
||||
}
|
||||
inline void PrismaticJoint::SetMotorSpeed(float speed)
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
raw_joint_->SetMotorSpeed(math::Degree2Radian(speed));
|
||||
}
|
||||
inline float PrismaticJoint::GetMotorSpeed() const
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
return math::Radian2Degree(raw_joint_->GetMotorSpeed());
|
||||
}
|
||||
inline void PrismaticJoint::SetMaxMotorForce(float force)
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
raw_joint_->SetMaxMotorForce(force);
|
||||
}
|
||||
inline float PrismaticJoint::GetMaxMotorForce() const
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
return raw_joint_->GetMaxMotorForce();
|
||||
}
|
||||
|
||||
inline float RevoluteJoint::GetReferenceAngle() const
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
return math::Radian2Degree(raw_joint_->GetReferenceAngle());
|
||||
}
|
||||
inline bool RevoluteJoint::IsLimitEnabled() const
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
return raw_joint_->IsLimitEnabled();
|
||||
}
|
||||
inline void RevoluteJoint::EnableLimit(bool flag)
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
raw_joint_->EnableLimit(flag);
|
||||
}
|
||||
inline bool RevoluteJoint::IsMotorEnabled() const
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
return raw_joint_->IsMotorEnabled();
|
||||
}
|
||||
inline void RevoluteJoint::EnableMotor(bool flag)
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
raw_joint_->EnableMotor(flag);
|
||||
}
|
||||
inline void RevoluteJoint::SetMotorSpeed(float speed)
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
raw_joint_->SetMotorSpeed(math::Degree2Radian(speed));
|
||||
}
|
||||
inline float RevoluteJoint::GetMotorSpeed() const
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
return math::Radian2Degree(raw_joint_->GetMotorSpeed());
|
||||
}
|
||||
|
||||
inline float WeldJoint::GetReferenceAngle() const
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
return math::Radian2Degree(raw_joint_->GetReferenceAngle());
|
||||
}
|
||||
inline void WeldJoint::SetFrequency(float hz)
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
raw_joint_->SetFrequency(hz);
|
||||
}
|
||||
inline float WeldJoint::GetFrequency() const
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
return raw_joint_->GetFrequency();
|
||||
}
|
||||
inline void WeldJoint::SetDampingRatio(float ratio)
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
raw_joint_->SetDampingRatio(ratio);
|
||||
}
|
||||
inline float WeldJoint::GetDampingRatio() const
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
return raw_joint_->GetDampingRatio();
|
||||
}
|
||||
|
||||
inline float WheelJoint::GetJointAngle() const
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
return math::Radian2Degree(raw_joint_->GetJointAngle());
|
||||
}
|
||||
inline float WheelJoint::GetJointAngularSpeed() const
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
return math::Radian2Degree(raw_joint_->GetJointAngularSpeed());
|
||||
}
|
||||
inline bool WheelJoint::IsMotorEnabled() const
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
return raw_joint_->IsMotorEnabled();
|
||||
}
|
||||
inline void WheelJoint::EnableMotor(bool flag)
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
raw_joint_->EnableMotor(flag);
|
||||
}
|
||||
inline void WheelJoint::SetMotorSpeed(float speed)
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
raw_joint_->SetMotorSpeed(math::Degree2Radian(speed));
|
||||
}
|
||||
inline float WheelJoint::GetMotorSpeed() const
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
return math::Radian2Degree(raw_joint_->GetMotorSpeed());
|
||||
}
|
||||
inline void WheelJoint::SetSpringFrequencyHz(float hz)
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
raw_joint_->SetSpringFrequencyHz(hz);
|
||||
}
|
||||
inline float WheelJoint::GetSpringFrequencyHz() const
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
return raw_joint_->GetSpringFrequencyHz();
|
||||
}
|
||||
inline void WheelJoint::SetSpringDampingRatio(float ratio)
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
raw_joint_->SetSpringDampingRatio(ratio);
|
||||
}
|
||||
inline float WheelJoint::GetSpringDampingRatio() const
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
return raw_joint_->GetSpringDampingRatio();
|
||||
}
|
||||
|
||||
inline void MouseJoint::SetFrequency(float hz)
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
raw_joint_->SetFrequency(hz);
|
||||
}
|
||||
inline float MouseJoint::GetFrequency() const
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
return raw_joint_->GetFrequency();
|
||||
}
|
||||
inline void MouseJoint::SetDampingRatio(float ratio)
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
raw_joint_->SetDampingRatio(ratio);
|
||||
}
|
||||
inline float MouseJoint::GetDampingRatio() const
|
||||
{
|
||||
KGE_ASSERT(raw_joint_);
|
||||
return raw_joint_->GetDampingRatio();
|
||||
}
|
||||
} // namespace physics
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -218,5 +218,5 @@ namespace kiwano
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace physics
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -55,8 +55,7 @@ namespace kiwano
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 圆形形状
|
||||
class KGE_API CircleShape
|
||||
: public Shape
|
||||
class KGE_API CircleShape : public Shape
|
||||
{
|
||||
public:
|
||||
CircleShape();
|
||||
|
|
@ -76,8 +75,7 @@ namespace kiwano
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 盒子形状
|
||||
class KGE_API BoxShape
|
||||
: public Shape
|
||||
class KGE_API BoxShape : public Shape
|
||||
{
|
||||
public:
|
||||
BoxShape();
|
||||
|
|
@ -98,8 +96,7 @@ namespace kiwano
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 多边形形状
|
||||
class KGE_API PolygonShape
|
||||
: public Shape
|
||||
class KGE_API PolygonShape : public Shape
|
||||
{
|
||||
public:
|
||||
PolygonShape();
|
||||
|
|
@ -118,8 +115,7 @@ namespace kiwano
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 线段形状, 用于表示一条边
|
||||
class KGE_API EdgeShape
|
||||
: public Shape
|
||||
class KGE_API EdgeShape : public Shape
|
||||
{
|
||||
public:
|
||||
EdgeShape();
|
||||
|
|
@ -138,8 +134,7 @@ namespace kiwano
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 链式形状
|
||||
class KGE_API ChainShape
|
||||
: public Shape
|
||||
class KGE_API ChainShape : public Shape
|
||||
{
|
||||
public:
|
||||
ChainShape();
|
||||
|
|
@ -158,5 +153,5 @@ namespace kiwano
|
|||
};
|
||||
|
||||
/** @} */
|
||||
}
|
||||
}
|
||||
} // namespace physics
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#include "World.h"
|
||||
|
||||
#include <kiwano-physics/ContactEvent.h>
|
||||
|
||||
namespace kiwano
|
||||
|
|
@ -48,14 +49,10 @@ namespace kiwano
|
|||
}
|
||||
}
|
||||
|
||||
void SayGoodbye(b2Fixture* fixture) override
|
||||
{
|
||||
|
||||
}
|
||||
void SayGoodbye(b2Fixture* fixture) override {}
|
||||
};
|
||||
|
||||
class World::ContactListener
|
||||
: public b2ContactListener
|
||||
class World::ContactListener : public b2ContactListener
|
||||
{
|
||||
World* world_;
|
||||
|
||||
|
|
@ -77,8 +74,16 @@ namespace kiwano
|
|||
world_->DispatchEvent(evt.get());
|
||||
}
|
||||
|
||||
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold) override { KGE_NOT_USED(contact); KGE_NOT_USED(oldManifold); }
|
||||
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse) override { KGE_NOT_USED(contact); KGE_NOT_USED(impulse); }
|
||||
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold) override
|
||||
{
|
||||
KGE_NOT_USED(contact);
|
||||
KGE_NOT_USED(oldManifold);
|
||||
}
|
||||
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse) override
|
||||
{
|
||||
KGE_NOT_USED(contact);
|
||||
KGE_NOT_USED(impulse);
|
||||
}
|
||||
};
|
||||
|
||||
World::World()
|
||||
|
|
@ -191,11 +196,8 @@ namespace kiwano
|
|||
{
|
||||
if (!removing_joint_ && joint)
|
||||
{
|
||||
auto iter = std::find_if(
|
||||
joints_.begin(),
|
||||
joints_.end(),
|
||||
[joint](Joint* j) -> bool { return j->GetB2Joint() == joint; }
|
||||
);
|
||||
auto iter = std::find_if(joints_.begin(), joints_.end(),
|
||||
[joint](Joint* j) -> bool { return j->GetB2Joint() == joint; });
|
||||
|
||||
if (iter != joints_.end())
|
||||
{
|
||||
|
|
@ -249,5 +251,5 @@ namespace kiwano
|
|||
Stage::Update(dt);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace physics
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -42,8 +42,7 @@ namespace kiwano
|
|||
* \~chinese
|
||||
* @brief 物理世界
|
||||
*/
|
||||
class KGE_API World
|
||||
: public Stage
|
||||
class KGE_API World : public Stage
|
||||
{
|
||||
friend class Body;
|
||||
friend class Joint;
|
||||
|
|
@ -153,7 +152,6 @@ namespace kiwano
|
|||
Vector<Joint*> joints_;
|
||||
};
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
inline float World::GetGlobalScale() const
|
||||
|
|
@ -195,5 +193,5 @@ namespace kiwano
|
|||
{
|
||||
pos_iter_ = pos_iter;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace physics
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -28,7 +28,13 @@ namespace kiwano
|
|||
{
|
||||
namespace physics
|
||||
{
|
||||
inline b2Vec2 Stage2World(const Vec2& pos) { return b2Vec2(pos.x, pos.y); }
|
||||
inline Vec2 World2Stage(const b2Vec2& pos) { return Vec2(pos.x, pos.y); }
|
||||
inline b2Vec2 Stage2World(const Vec2& pos)
|
||||
{
|
||||
return b2Vec2(pos.x, pos.y);
|
||||
}
|
||||
inline Vec2 World2Stage(const b2Vec2& pos)
|
||||
{
|
||||
return Vec2(pos.x, pos.y);
|
||||
}
|
||||
} // namespace physics
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <kiwano-physics/Shape.h>
|
||||
#include <kiwano-physics/Fixture.h>
|
||||
#include <kiwano-physics/Body.h>
|
||||
#include <kiwano-physics/Contact.h>
|
||||
#include <kiwano-physics/ContactEvent.h>
|
||||
#include <kiwano-physics/Body.h>
|
||||
#include <kiwano-physics/Fixture.h>
|
||||
#include <kiwano-physics/Joint.h>
|
||||
#include <kiwano-physics/Shape.h>
|
||||
#include <kiwano-physics/World.h>
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ namespace kiwano
|
|||
{
|
||||
float default_anchor_x = 0.f;
|
||||
float default_anchor_y = 0.f;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void Actor::SetDefaultAnchor(float anchor_x, float anchor_y)
|
||||
{
|
||||
|
|
@ -60,9 +60,7 @@ namespace kiwano
|
|||
{
|
||||
}
|
||||
|
||||
Actor::~Actor()
|
||||
{
|
||||
}
|
||||
Actor::~Actor() {}
|
||||
|
||||
void Actor::Update(Duration dt)
|
||||
{
|
||||
|
|
@ -610,7 +608,8 @@ namespace kiwano
|
|||
if (child)
|
||||
{
|
||||
child->parent_ = nullptr;
|
||||
if (child->stage_) child->SetStage(nullptr);
|
||||
if (child->stage_)
|
||||
child->SetStage(nullptr);
|
||||
children_.remove(ActorPtr(child));
|
||||
}
|
||||
}
|
||||
|
|
@ -655,4 +654,4 @@ namespace kiwano
|
|||
return GetBounds().ContainsPoint(local);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -19,13 +19,13 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano/math/math.h>
|
||||
#include <kiwano/core/Time.h>
|
||||
#include <kiwano/core/ObjectBase.h>
|
||||
#include <kiwano/core/TimerManager.h>
|
||||
#include <kiwano/core/EventDispatcher.h>
|
||||
#include <kiwano/2d/Transform.h>
|
||||
#include <kiwano/2d/action/ActionManager.h>
|
||||
#include <kiwano/core/EventDispatcher.h>
|
||||
#include <kiwano/core/ObjectBase.h>
|
||||
#include <kiwano/core/Time.h>
|
||||
#include <kiwano/core/TimerManager.h>
|
||||
#include <kiwano/math/math.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -48,7 +48,8 @@ namespace kiwano
|
|||
/**
|
||||
* \~chinese
|
||||
* @brief 角色
|
||||
* @details 角色是舞台上最基本的元素,是完成渲染、更新、事件分发等功能的最小单位,也是动画、定时器、事件监听等功能的载体
|
||||
* @details
|
||||
* 角色是舞台上最基本的元素,是完成渲染、更新、事件分发等功能的最小单位,也是动画、定时器、事件监听等功能的载体
|
||||
*/
|
||||
class KGE_API Actor
|
||||
: public virtual ObjectBase
|
||||
|
|
@ -82,7 +83,8 @@ namespace kiwano
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 渲染角色
|
||||
/// @details 每帧画面刷新时调用该函数,默认不进行渲染,重载该函数以实现具体渲染过程
|
||||
/// @details
|
||||
/// 每帧画面刷新时调用该函数,默认不进行渲染,重载该函数以实现具体渲染过程
|
||||
/// @param ctx 渲染上下文
|
||||
virtual void OnRender(RenderContext& ctx);
|
||||
|
||||
|
|
@ -473,7 +475,6 @@ namespace kiwano
|
|||
|
||||
/** @} */
|
||||
|
||||
|
||||
inline void Actor::OnUpdate(Duration dt)
|
||||
{
|
||||
KGE_NOT_USED(dt);
|
||||
|
|
@ -688,5 +689,4 @@ namespace kiwano
|
|||
{
|
||||
SetSkew(Vec2{ skewx, skewy });
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -45,9 +45,7 @@ namespace kiwano
|
|||
this->SetMouseOutCallback(mouse_out);
|
||||
}
|
||||
|
||||
Button::~Button()
|
||||
{
|
||||
}
|
||||
Button::~Button() {}
|
||||
|
||||
bool Button::IsEnable() const
|
||||
{
|
||||
|
|
@ -158,7 +156,6 @@ namespace kiwano
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
SpriteButton::SpriteButton()
|
||||
: SpriteButton(nullptr, nullptr, nullptr, nullptr)
|
||||
{
|
||||
|
|
@ -169,7 +166,8 @@ namespace kiwano
|
|||
{
|
||||
}
|
||||
|
||||
SpriteButton::SpriteButton(Callback const& click, Callback const& pressed, Callback const& mouse_over, Callback const& mouse_out)
|
||||
SpriteButton::SpriteButton(Callback const& click, Callback const& pressed, Callback const& mouse_over,
|
||||
Callback const& mouse_out)
|
||||
: Button(click, pressed, mouse_over, mouse_out)
|
||||
{
|
||||
SetResponsible(true);
|
||||
|
|
@ -182,7 +180,6 @@ namespace kiwano
|
|||
AddListener<MouseClickEvent>(handler);
|
||||
}
|
||||
|
||||
|
||||
TextButton::TextButton()
|
||||
: TextButton(nullptr, nullptr, nullptr, nullptr)
|
||||
{
|
||||
|
|
@ -193,7 +190,8 @@ namespace kiwano
|
|||
{
|
||||
}
|
||||
|
||||
TextButton::TextButton(Callback const& click, Callback const& pressed, Callback const& mouse_over, Callback const& mouse_out)
|
||||
TextButton::TextButton(Callback const& click, Callback const& pressed, Callback const& mouse_over,
|
||||
Callback const& mouse_out)
|
||||
: Button(click, pressed, mouse_over, mouse_out)
|
||||
{
|
||||
SetResponsible(true);
|
||||
|
|
@ -206,4 +204,4 @@ namespace kiwano
|
|||
AddListener<MouseClickEvent>(handler);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -32,8 +32,7 @@ namespace kiwano
|
|||
* \~chinese
|
||||
* @brief 按钮
|
||||
*/
|
||||
class KGE_API Button
|
||||
: public virtual ObjectBase
|
||||
class KGE_API Button : public virtual ObjectBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -117,7 +116,6 @@ namespace kiwano
|
|||
Callback mouse_out_callback_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 精灵按钮
|
||||
class SpriteButton
|
||||
|
|
@ -141,7 +139,6 @@ namespace kiwano
|
|||
SpriteButton(Callback const& click, Callback const& pressed, Callback const& mouse_over, Callback const& mouse_out);
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 文字按钮
|
||||
class TextButton
|
||||
|
|
@ -164,4 +161,4 @@ namespace kiwano
|
|||
/// @param mouse_out 按钮移出回调函数
|
||||
TextButton(Callback const& click, Callback const& pressed, Callback const& mouse_over, Callback const& mouse_out);
|
||||
};
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -31,9 +31,7 @@ namespace kiwano
|
|||
{
|
||||
}
|
||||
|
||||
Canvas::~Canvas()
|
||||
{
|
||||
}
|
||||
Canvas::~Canvas() {}
|
||||
|
||||
void Canvas::BeginDraw()
|
||||
{
|
||||
|
|
@ -112,12 +110,7 @@ namespace kiwano
|
|||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
ctx_->SetCurrentBrush(stroke_brush_);
|
||||
ctx_->DrawLine(
|
||||
begin,
|
||||
end,
|
||||
stroke_width_,
|
||||
stroke_style_
|
||||
);
|
||||
ctx_->DrawLine(begin, end, stroke_width_, stroke_style_);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
||||
|
|
@ -125,12 +118,7 @@ namespace kiwano
|
|||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
ctx_->SetCurrentBrush(stroke_brush_);
|
||||
ctx_->DrawEllipse(
|
||||
center,
|
||||
Vec2(radius, radius),
|
||||
stroke_width_,
|
||||
stroke_style_
|
||||
);
|
||||
ctx_->DrawEllipse(center, Vec2(radius, radius), stroke_width_, stroke_style_);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
||||
|
|
@ -138,12 +126,7 @@ namespace kiwano
|
|||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
ctx_->SetCurrentBrush(stroke_brush_);
|
||||
ctx_->DrawEllipse(
|
||||
center,
|
||||
radius,
|
||||
stroke_width_,
|
||||
stroke_style_
|
||||
);
|
||||
ctx_->DrawEllipse(center, radius, stroke_width_, stroke_style_);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
||||
|
|
@ -151,11 +134,7 @@ namespace kiwano
|
|||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
ctx_->SetCurrentBrush(stroke_brush_);
|
||||
ctx_->DrawRectangle(
|
||||
rect,
|
||||
stroke_width_,
|
||||
stroke_style_
|
||||
);
|
||||
ctx_->DrawRectangle(rect, stroke_width_, stroke_style_);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
||||
|
|
@ -163,12 +142,7 @@ namespace kiwano
|
|||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
ctx_->SetCurrentBrush(stroke_brush_);
|
||||
ctx_->DrawRoundedRectangle(
|
||||
rect,
|
||||
radius,
|
||||
stroke_width_,
|
||||
stroke_style_
|
||||
);
|
||||
ctx_->DrawRoundedRectangle(rect, radius, stroke_width_, stroke_style_);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
||||
|
|
@ -176,10 +150,7 @@ namespace kiwano
|
|||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
ctx_->SetCurrentBrush(fill_brush_);
|
||||
ctx_->FillEllipse(
|
||||
center,
|
||||
Vec2(radius, radius)
|
||||
);
|
||||
ctx_->FillEllipse(center, Vec2(radius, radius));
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
||||
|
|
@ -187,10 +158,7 @@ namespace kiwano
|
|||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
ctx_->SetCurrentBrush(fill_brush_);
|
||||
ctx_->FillEllipse(
|
||||
center,
|
||||
radius
|
||||
);
|
||||
ctx_->FillEllipse(center, radius);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
||||
|
|
@ -198,9 +166,7 @@ namespace kiwano
|
|||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
ctx_->SetCurrentBrush(fill_brush_);
|
||||
ctx_->FillRectangle(
|
||||
rect
|
||||
);
|
||||
ctx_->FillRectangle(rect);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
||||
|
|
@ -208,10 +174,7 @@ namespace kiwano
|
|||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
ctx_->SetCurrentBrush(fill_brush_);
|
||||
ctx_->FillRoundedRectangle(
|
||||
rect,
|
||||
radius
|
||||
);
|
||||
ctx_->FillRoundedRectangle(rect, radius);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
||||
|
|
@ -276,11 +239,7 @@ namespace kiwano
|
|||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
ctx_->SetCurrentBrush(stroke_brush_);
|
||||
ctx_->DrawGeometry(
|
||||
geo_sink_.GetGeometry(),
|
||||
stroke_width_,
|
||||
stroke_style_
|
||||
);
|
||||
ctx_->DrawGeometry(geo_sink_.GetGeometry(), stroke_width_, stroke_style_);
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
||||
|
|
@ -288,9 +247,7 @@ namespace kiwano
|
|||
{
|
||||
InitRenderTargetAndBrushs();
|
||||
ctx_->SetCurrentBrush(fill_brush_);
|
||||
ctx_->FillGeometry(
|
||||
geo_sink_.GetGeometry()
|
||||
);
|
||||
ctx_->FillGeometry(geo_sink_.GetGeometry());
|
||||
cache_expired_ = true;
|
||||
}
|
||||
|
||||
|
|
@ -350,4 +307,4 @@ namespace kiwano
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@
|
|||
|
||||
#pragma once
|
||||
#include <kiwano/2d/Actor.h>
|
||||
#include <kiwano/render/RenderContext.h>
|
||||
#include <kiwano/render/GeometrySink.h>
|
||||
#include <kiwano/render/RenderContext.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -36,8 +36,7 @@ namespace kiwano
|
|||
* \~chinese
|
||||
* @brief 画布,用于绘制图元
|
||||
*/
|
||||
class KGE_API Canvas
|
||||
: public Actor
|
||||
class KGE_API Canvas : public Actor
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -330,5 +329,4 @@ namespace kiwano
|
|||
{
|
||||
return stroke_brush_;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#include <kiwano/2d/DebugActor.h>
|
||||
#include <kiwano/render/Renderer.h>
|
||||
#include <kiwano/core/Logger.h>
|
||||
#include <kiwano/render/Renderer.h>
|
||||
#include <psapi.h>
|
||||
|
||||
#pragma comment(lib, "psapi.lib")
|
||||
|
|
@ -42,7 +42,7 @@ namespace kiwano
|
|||
return "\03";
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
DebugActor::DebugActor()
|
||||
{
|
||||
|
|
@ -71,9 +71,7 @@ namespace kiwano
|
|||
AddListener<MouseOutEvent>([=](Event*) { SetOpacity(1.f); });
|
||||
}
|
||||
|
||||
DebugActor::~DebugActor()
|
||||
{
|
||||
}
|
||||
DebugActor::~DebugActor() {}
|
||||
|
||||
void DebugActor::OnRender(RenderContext& ctx)
|
||||
{
|
||||
|
|
@ -108,7 +106,8 @@ namespace kiwano
|
|||
|
||||
ss << "Render: " << Renderer::Instance().GetStatus().duration.Milliseconds() << "ms" << std::endl;
|
||||
|
||||
ss << "Primitives / sec: " << std::fixed << Renderer::Instance().GetStatus().primitives * frame_time_.size() << std::endl;
|
||||
ss << "Primitives / sec: " << std::fixed << Renderer::Instance().GetStatus().primitives * frame_time_.size()
|
||||
<< std::endl;
|
||||
|
||||
ss << "Memory: ";
|
||||
{
|
||||
|
|
@ -144,4 +143,4 @@ namespace kiwano
|
|||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -33,8 +33,7 @@ namespace kiwano
|
|||
* \~chinese
|
||||
* @brief 调试节点
|
||||
*/
|
||||
class KGE_API DebugActor
|
||||
: public Actor
|
||||
class KGE_API DebugActor : public Actor
|
||||
{
|
||||
public:
|
||||
DebugActor();
|
||||
|
|
@ -56,5 +55,4 @@ namespace kiwano
|
|||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -23,9 +23,7 @@
|
|||
|
||||
namespace kiwano
|
||||
{
|
||||
Frame::Frame()
|
||||
{
|
||||
}
|
||||
Frame::Frame() {}
|
||||
|
||||
bool Frame::Load(String const& file_path)
|
||||
{
|
||||
|
|
@ -71,4 +69,4 @@ namespace kiwano
|
|||
crop_rect_.right_bottom.y = texture_->GetHeight();
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -30,8 +30,7 @@ namespace kiwano
|
|||
* \~chinese
|
||||
* @brief ͼÏñÖ¡
|
||||
*/
|
||||
class KGE_API Frame
|
||||
: public virtual ObjectBase
|
||||
class KGE_API Frame : public virtual ObjectBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -91,11 +90,32 @@ namespace kiwano
|
|||
Rect crop_rect_;
|
||||
};
|
||||
|
||||
inline bool Frame::IsValid() const { return texture_ && texture_->IsValid(); }
|
||||
inline float Frame::GetWidth() const { return crop_rect_.GetWidth(); }
|
||||
inline float Frame::GetHeight() const { return crop_rect_.GetHeight(); }
|
||||
inline Size Frame::GetSize() const { return crop_rect_.GetSize(); }
|
||||
inline Point Frame::GetCropPoint() const { return crop_rect_.GetLeftTop(); }
|
||||
inline Rect const& Frame::GetCropRect() const { return crop_rect_; }
|
||||
inline TexturePtr Frame::GetTexture() const { return texture_; }
|
||||
inline bool Frame::IsValid() const
|
||||
{
|
||||
return texture_ && texture_->IsValid();
|
||||
}
|
||||
inline float Frame::GetWidth() const
|
||||
{
|
||||
return crop_rect_.GetWidth();
|
||||
}
|
||||
inline float Frame::GetHeight() const
|
||||
{
|
||||
return crop_rect_.GetHeight();
|
||||
}
|
||||
inline Size Frame::GetSize() const
|
||||
{
|
||||
return crop_rect_.GetSize();
|
||||
}
|
||||
inline Point Frame::GetCropPoint() const
|
||||
{
|
||||
return crop_rect_.GetLeftTop();
|
||||
}
|
||||
inline Rect const& Frame::GetCropRect() const
|
||||
{
|
||||
return crop_rect_;
|
||||
}
|
||||
inline TexturePtr Frame::GetTexture() const
|
||||
{
|
||||
return texture_;
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -23,18 +23,14 @@
|
|||
|
||||
namespace kiwano
|
||||
{
|
||||
FrameSequence::FrameSequence()
|
||||
{
|
||||
}
|
||||
FrameSequence::FrameSequence() {}
|
||||
|
||||
FrameSequence::FrameSequence(Vector<FramePtr> const& frames)
|
||||
{
|
||||
this->AddFrames(frames);
|
||||
}
|
||||
|
||||
FrameSequence::~FrameSequence()
|
||||
{
|
||||
}
|
||||
FrameSequence::~FrameSequence() {}
|
||||
|
||||
void FrameSequence::AddFrame(FramePtr frame)
|
||||
{
|
||||
|
|
@ -98,4 +94,4 @@ namespace kiwano
|
|||
return frame_seq;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano/2d/Frame.h>
|
||||
#include <kiwano/core/Common.h>
|
||||
#include <kiwano/core/Time.h>
|
||||
#include <kiwano/2d/Frame.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -31,8 +31,7 @@ namespace kiwano
|
|||
* \~chinese
|
||||
* @brief ÐòÁÐÖ¡
|
||||
*/
|
||||
class KGE_API FrameSequence
|
||||
: public virtual ObjectBase
|
||||
class KGE_API FrameSequence : public virtual ObjectBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -80,4 +79,4 @@ namespace kiwano
|
|||
private:
|
||||
Vector<FramePtr> frames_;
|
||||
};
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#include <kiwano/2d/GifSprite.h>
|
||||
#include <kiwano/render/TextureCache.h>
|
||||
#include <kiwano/render/Renderer.h>
|
||||
#include <kiwano/render/TextureCache.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -206,7 +206,8 @@ namespace kiwano
|
|||
if (!saved_frame_)
|
||||
{
|
||||
saved_frame_ = new Texture;
|
||||
frame_rt_->CreateTexture(*saved_frame_, frame_to_be_saved->GetSizeInPixels(), frame_to_be_saved->GetPixelFormat());
|
||||
frame_rt_->CreateTexture(*saved_frame_, frame_to_be_saved->GetSizeInPixels(),
|
||||
frame_to_be_saved->GetPixelFormat());
|
||||
}
|
||||
|
||||
saved_frame_->CopyFrom(frame_to_be_saved);
|
||||
|
|
@ -240,4 +241,4 @@ namespace kiwano
|
|||
return frame_rt_->EndDraw();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@
|
|||
#pragma once
|
||||
#include <kiwano/2d/Actor.h>
|
||||
#include <kiwano/core/Resource.h>
|
||||
#include <kiwano/render/RenderContext.h>
|
||||
#include <kiwano/render/GifImage.h>
|
||||
#include <kiwano/render/RenderContext.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -37,8 +37,7 @@ namespace kiwano
|
|||
* \~chinese
|
||||
* @brief GIF ¾«Áé
|
||||
*/
|
||||
class KGE_API GifSprite
|
||||
: public Actor
|
||||
class KGE_API GifSprite : public Actor
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -152,19 +151,43 @@ namespace kiwano
|
|||
|
||||
/** @} */
|
||||
|
||||
inline void GifSprite::SetLoopCount(int loops) { total_loop_count_ = loops; }
|
||||
|
||||
inline void GifSprite::SetLoopDoneCallback(LoopDoneCallback const& cb) { loop_cb_ = cb; }
|
||||
|
||||
inline void GifSprite::SetDoneCallback(DoneCallback const& cb) { done_cb_ = cb; }
|
||||
|
||||
inline GifSprite::LoopDoneCallback GifSprite::GetLoopDoneCallback() const { return loop_cb_; }
|
||||
|
||||
inline GifSprite::DoneCallback GifSprite::GetDoneCallback() const { return done_cb_; }
|
||||
|
||||
inline GifImagePtr GifSprite::GetGifImage() const { return gif_; }
|
||||
|
||||
inline bool GifSprite::IsLastFrame() const { return (next_index_ == 0); }
|
||||
|
||||
inline bool GifSprite::EndOfAnimation() const { return IsLastFrame() && loop_count_ == total_loop_count_ + 1; }
|
||||
inline void GifSprite::SetLoopCount(int loops)
|
||||
{
|
||||
total_loop_count_ = loops;
|
||||
}
|
||||
|
||||
inline void GifSprite::SetLoopDoneCallback(LoopDoneCallback const& cb)
|
||||
{
|
||||
loop_cb_ = cb;
|
||||
}
|
||||
|
||||
inline void GifSprite::SetDoneCallback(DoneCallback const& cb)
|
||||
{
|
||||
done_cb_ = cb;
|
||||
}
|
||||
|
||||
inline GifSprite::LoopDoneCallback GifSprite::GetLoopDoneCallback() const
|
||||
{
|
||||
return loop_cb_;
|
||||
}
|
||||
|
||||
inline GifSprite::DoneCallback GifSprite::GetDoneCallback() const
|
||||
{
|
||||
return done_cb_;
|
||||
}
|
||||
|
||||
inline GifImagePtr GifSprite::GetGifImage() const
|
||||
{
|
||||
return gif_;
|
||||
}
|
||||
|
||||
inline bool GifSprite::IsLastFrame() const
|
||||
{
|
||||
return (next_index_ == 0);
|
||||
}
|
||||
|
||||
inline bool GifSprite::EndOfAnimation() const
|
||||
{
|
||||
return IsLastFrame() && loop_count_ == total_loop_count_ + 1;
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -29,9 +29,7 @@ namespace kiwano
|
|||
{
|
||||
}
|
||||
|
||||
Layer::~Layer()
|
||||
{
|
||||
}
|
||||
Layer::~Layer() {}
|
||||
|
||||
void Layer::SetClipRect(Rect const& clip_rect)
|
||||
{
|
||||
|
|
@ -81,4 +79,4 @@ namespace kiwano
|
|||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -36,8 +36,7 @@ namespace kiwano
|
|||
* \~chinese
|
||||
* @brief ͼ²ã
|
||||
*/
|
||||
class KGE_API Layer
|
||||
: public Actor
|
||||
class KGE_API Layer : public Actor
|
||||
{
|
||||
public:
|
||||
Layer();
|
||||
|
|
@ -96,12 +95,23 @@ namespace kiwano
|
|||
|
||||
/** @} */
|
||||
|
||||
inline bool Layer::IsSwallowEventsEnabled() const { return swallow_; }
|
||||
|
||||
inline void Layer::SetSwallowEvents(bool enabled) { swallow_ = enabled; }
|
||||
|
||||
inline void Layer::SetArea(LayerArea const& area) { area_ = area; }
|
||||
|
||||
inline LayerArea const& Layer::GetArea() const { return area_; }
|
||||
|
||||
inline bool Layer::IsSwallowEventsEnabled() const
|
||||
{
|
||||
return swallow_;
|
||||
}
|
||||
|
||||
inline void Layer::SetSwallowEvents(bool enabled)
|
||||
{
|
||||
swallow_ = enabled;
|
||||
}
|
||||
|
||||
inline void Layer::SetArea(LayerArea const& area)
|
||||
{
|
||||
area_ = area;
|
||||
}
|
||||
|
||||
inline LayerArea const& Layer::GetArea() const
|
||||
{
|
||||
return area_;
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -30,9 +30,7 @@ namespace kiwano
|
|||
{
|
||||
}
|
||||
|
||||
ShapeActor::~ShapeActor()
|
||||
{
|
||||
}
|
||||
ShapeActor::~ShapeActor() {}
|
||||
|
||||
Rect ShapeActor::GetBounds() const
|
||||
{
|
||||
|
|
@ -108,13 +106,9 @@ namespace kiwano
|
|||
// LineActor
|
||||
//-------------------------------------------------------
|
||||
|
||||
LineActor::LineActor()
|
||||
{
|
||||
}
|
||||
LineActor::LineActor() {}
|
||||
|
||||
LineActor::~LineActor()
|
||||
{
|
||||
}
|
||||
LineActor::~LineActor() {}
|
||||
|
||||
void LineActor::SetLine(Point const& begin, Point const& end)
|
||||
{
|
||||
|
|
@ -126,18 +120,13 @@ namespace kiwano
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------
|
||||
// RectActor
|
||||
//-------------------------------------------------------
|
||||
|
||||
RectActor::RectActor()
|
||||
{
|
||||
}
|
||||
RectActor::RectActor() {}
|
||||
|
||||
RectActor::~RectActor()
|
||||
{
|
||||
}
|
||||
RectActor::~RectActor() {}
|
||||
|
||||
void RectActor::SetRectSize(Size const& size)
|
||||
{
|
||||
|
|
@ -148,18 +137,13 @@ namespace kiwano
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------
|
||||
// RoundRectActor
|
||||
//-------------------------------------------------------
|
||||
|
||||
RoundRectActor::RoundRectActor()
|
||||
{
|
||||
}
|
||||
RoundRectActor::RoundRectActor() {}
|
||||
|
||||
RoundRectActor::~RoundRectActor()
|
||||
{
|
||||
}
|
||||
RoundRectActor::~RoundRectActor() {}
|
||||
|
||||
void RoundRectActor::SetRadius(Vec2 const& radius)
|
||||
{
|
||||
|
|
@ -181,7 +165,6 @@ namespace kiwano
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------
|
||||
// CircleActor
|
||||
//-------------------------------------------------------
|
||||
|
|
@ -191,9 +174,7 @@ namespace kiwano
|
|||
{
|
||||
}
|
||||
|
||||
CircleActor::~CircleActor()
|
||||
{
|
||||
}
|
||||
CircleActor::~CircleActor() {}
|
||||
|
||||
void CircleActor::SetRadius(float radius)
|
||||
{
|
||||
|
|
@ -204,18 +185,13 @@ namespace kiwano
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------
|
||||
// EllipseActor
|
||||
//-------------------------------------------------------
|
||||
|
||||
EllipseActor::EllipseActor()
|
||||
{
|
||||
}
|
||||
EllipseActor::EllipseActor() {}
|
||||
|
||||
EllipseActor::~EllipseActor()
|
||||
{
|
||||
}
|
||||
EllipseActor::~EllipseActor() {}
|
||||
|
||||
void EllipseActor::SetRadius(Vec2 const& radius)
|
||||
{
|
||||
|
|
@ -226,45 +202,30 @@ namespace kiwano
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------
|
||||
// PolygonActor
|
||||
//-------------------------------------------------------
|
||||
|
||||
PolygonActor::PolygonActor()
|
||||
{
|
||||
}
|
||||
PolygonActor::PolygonActor() {}
|
||||
|
||||
PolygonActor::~PolygonActor()
|
||||
{
|
||||
}
|
||||
PolygonActor::~PolygonActor() {}
|
||||
|
||||
void PolygonActor::SetVertices(Vector<Point> const& points)
|
||||
{
|
||||
if (points.size() > 1)
|
||||
{
|
||||
SetGeometry(
|
||||
GeometrySink()
|
||||
.BeginPath(points[0])
|
||||
.AddLines(&points[1], points.size() - 1)
|
||||
.EndPath(true)
|
||||
.GetGeometry()
|
||||
);
|
||||
GeometrySink().BeginPath(points[0]).AddLines(&points[1], points.size() - 1).EndPath(true).GetGeometry());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------
|
||||
// PathShapeActor
|
||||
//-------------------------------------------------------
|
||||
|
||||
PathShapeActor::PathShapeActor()
|
||||
{
|
||||
}
|
||||
PathShapeActor::PathShapeActor() {}
|
||||
|
||||
PathShapeActor::~PathShapeActor()
|
||||
{
|
||||
}
|
||||
PathShapeActor::~PathShapeActor() {}
|
||||
|
||||
void PathShapeActor::BeginPath(Point const& begin_pos)
|
||||
{
|
||||
|
|
@ -307,4 +268,4 @@ namespace kiwano
|
|||
SetGeometry(Geometry());
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -45,8 +45,7 @@ namespace kiwano
|
|||
* \~chinese
|
||||
* @brief 二维形状角色
|
||||
*/
|
||||
class KGE_API ShapeActor
|
||||
: public Actor
|
||||
class KGE_API ShapeActor : public Actor
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -133,11 +132,9 @@ namespace kiwano
|
|||
Geometry geo_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 线段图形角色
|
||||
class KGE_API LineActor
|
||||
: public ShapeActor
|
||||
class KGE_API LineActor : public ShapeActor
|
||||
{
|
||||
public:
|
||||
LineActor();
|
||||
|
|
@ -173,11 +170,9 @@ namespace kiwano
|
|||
Point end_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 矩形角色
|
||||
class KGE_API RectActor
|
||||
: public ShapeActor
|
||||
class KGE_API RectActor : public ShapeActor
|
||||
{
|
||||
public:
|
||||
RectActor();
|
||||
|
|
@ -197,12 +192,9 @@ namespace kiwano
|
|||
Size rect_size_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 圆角矩形角色
|
||||
class KGE_API RoundRectActor
|
||||
: public ShapeActor
|
||||
class KGE_API RoundRectActor : public ShapeActor
|
||||
{
|
||||
public:
|
||||
RoundRectActor();
|
||||
|
|
@ -238,11 +230,9 @@ namespace kiwano
|
|||
Vec2 radius_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 圆形角色
|
||||
class KGE_API CircleActor
|
||||
: public ShapeActor
|
||||
class KGE_API CircleActor : public ShapeActor
|
||||
{
|
||||
public:
|
||||
CircleActor();
|
||||
|
|
@ -262,11 +252,9 @@ namespace kiwano
|
|||
float radius_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 椭圆角色
|
||||
class KGE_API EllipseActor
|
||||
: public ShapeActor
|
||||
class KGE_API EllipseActor : public ShapeActor
|
||||
{
|
||||
public:
|
||||
EllipseActor();
|
||||
|
|
@ -286,11 +274,9 @@ namespace kiwano
|
|||
Vec2 radius_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 多边形角色
|
||||
class KGE_API PolygonActor
|
||||
: public ShapeActor
|
||||
class KGE_API PolygonActor : public ShapeActor
|
||||
{
|
||||
public:
|
||||
PolygonActor();
|
||||
|
|
@ -303,11 +289,9 @@ namespace kiwano
|
|||
void SetVertices(Vector<Point> const& points);
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 路径图形角色
|
||||
class KGE_API PathShapeActor
|
||||
: public ShapeActor
|
||||
class KGE_API PathShapeActor : public ShapeActor
|
||||
{
|
||||
public:
|
||||
PathShapeActor();
|
||||
|
|
@ -378,25 +362,73 @@ namespace kiwano
|
|||
fill_brush_->SetColor(color);
|
||||
}
|
||||
|
||||
inline void ShapeActor::SetFillBrush(BrushPtr brush) { fill_brush_ = brush; }
|
||||
inline void ShapeActor::SetStrokeBrush(BrushPtr brush) { stroke_brush_ = brush; }
|
||||
inline BrushPtr ShapeActor::GetFillBrush() const { return fill_brush_; }
|
||||
inline BrushPtr ShapeActor::GetStrokeBrush() const { return stroke_brush_; }
|
||||
inline float ShapeActor::GetStrokeWidth() const { return stroke_width_; }
|
||||
inline const StrokeStyle& ShapeActor::GetStrokeStyle() const { return stroke_style_; }
|
||||
inline Geometry ShapeActor::GetGeometry() const { return geo_; }
|
||||
|
||||
inline Point const& LineActor::GetBeginPoint() const { return begin_; }
|
||||
inline Point const& LineActor::GetEndPoint() const { return end_; }
|
||||
inline void LineActor::SetBeginPoint(Point const& begin) { SetLine(begin, end_); }
|
||||
inline void LineActor::SetEndPoint(Point const& end) { SetLine(begin_, end); }
|
||||
|
||||
inline Size const& RectActor::GetRectSize() const { return rect_size_; }
|
||||
|
||||
inline Vec2 RoundRectActor::GetRadius() const { return radius_; }
|
||||
inline Size RoundRectActor::GetRectSize() const { return GetSize(); }
|
||||
|
||||
inline float CircleActor::GetRadius() const { return radius_; }
|
||||
|
||||
inline Vec2 EllipseActor::GetRadius() const { return radius_; }
|
||||
inline void ShapeActor::SetFillBrush(BrushPtr brush)
|
||||
{
|
||||
fill_brush_ = brush;
|
||||
}
|
||||
inline void ShapeActor::SetStrokeBrush(BrushPtr brush)
|
||||
{
|
||||
stroke_brush_ = brush;
|
||||
}
|
||||
inline BrushPtr ShapeActor::GetFillBrush() const
|
||||
{
|
||||
return fill_brush_;
|
||||
}
|
||||
inline BrushPtr ShapeActor::GetStrokeBrush() const
|
||||
{
|
||||
return stroke_brush_;
|
||||
}
|
||||
inline float ShapeActor::GetStrokeWidth() const
|
||||
{
|
||||
return stroke_width_;
|
||||
}
|
||||
inline const StrokeStyle& ShapeActor::GetStrokeStyle() const
|
||||
{
|
||||
return stroke_style_;
|
||||
}
|
||||
inline Geometry ShapeActor::GetGeometry() const
|
||||
{
|
||||
return geo_;
|
||||
}
|
||||
|
||||
inline Point const& LineActor::GetBeginPoint() const
|
||||
{
|
||||
return begin_;
|
||||
}
|
||||
inline Point const& LineActor::GetEndPoint() const
|
||||
{
|
||||
return end_;
|
||||
}
|
||||
inline void LineActor::SetBeginPoint(Point const& begin)
|
||||
{
|
||||
SetLine(begin, end_);
|
||||
}
|
||||
inline void LineActor::SetEndPoint(Point const& end)
|
||||
{
|
||||
SetLine(begin_, end);
|
||||
}
|
||||
|
||||
inline Size const& RectActor::GetRectSize() const
|
||||
{
|
||||
return rect_size_;
|
||||
}
|
||||
|
||||
inline Vec2 RoundRectActor::GetRadius() const
|
||||
{
|
||||
return radius_;
|
||||
}
|
||||
inline Size RoundRectActor::GetRectSize() const
|
||||
{
|
||||
return GetSize();
|
||||
}
|
||||
|
||||
inline float CircleActor::GetRadius() const
|
||||
{
|
||||
return radius_;
|
||||
}
|
||||
|
||||
inline Vec2 EllipseActor::GetRadius() const
|
||||
{
|
||||
return radius_;
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -23,13 +23,9 @@
|
|||
|
||||
namespace kiwano
|
||||
{
|
||||
Sprite::Sprite()
|
||||
{
|
||||
}
|
||||
Sprite::Sprite() {}
|
||||
|
||||
Sprite::~Sprite()
|
||||
{
|
||||
}
|
||||
Sprite::~Sprite() {}
|
||||
|
||||
bool Sprite::Load(String const& file_path)
|
||||
{
|
||||
|
|
@ -83,4 +79,4 @@ namespace kiwano
|
|||
{
|
||||
return frame_ && frame_->IsValid() && Actor::CheckVisibility(ctx);
|
||||
}
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -35,8 +35,7 @@ namespace kiwano
|
|||
* \~chinese
|
||||
* @brief ¾«Áé
|
||||
*/
|
||||
class KGE_API Sprite
|
||||
: public Actor
|
||||
class KGE_API Sprite : public Actor
|
||||
{
|
||||
public:
|
||||
Sprite();
|
||||
|
|
@ -78,6 +77,8 @@ namespace kiwano
|
|||
|
||||
/** @} */
|
||||
|
||||
inline FramePtr Sprite::GetFrame() const { return frame_; }
|
||||
|
||||
inline FramePtr Sprite::GetFrame() const
|
||||
{
|
||||
return frame_;
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -32,9 +32,7 @@ namespace kiwano
|
|||
SetSize(Renderer::Instance().GetOutputSize());
|
||||
}
|
||||
|
||||
Stage::~Stage()
|
||||
{
|
||||
}
|
||||
Stage::~Stage() {}
|
||||
|
||||
void Stage::OnEnter()
|
||||
{
|
||||
|
|
@ -65,4 +63,4 @@ namespace kiwano
|
|||
Actor::RenderBorder(ctx);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -37,8 +37,7 @@ namespace kiwano
|
|||
* @details 舞台是所有角色的载体,是导演直接控制的对象
|
||||
* @see kiwano::Actor kiwano::Director
|
||||
*/
|
||||
class KGE_API Stage
|
||||
: public Actor
|
||||
class KGE_API Stage : public Actor
|
||||
{
|
||||
friend class Transition;
|
||||
friend class Director;
|
||||
|
|
@ -105,5 +104,4 @@ namespace kiwano
|
|||
{
|
||||
border_stroke_brush_ = brush;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ namespace kiwano
|
|||
text_default_style.fill_brush->SetColor(Color::White);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void TextActor::SetDefaultStyle(TextStyle const& style)
|
||||
{
|
||||
|
|
@ -71,9 +71,7 @@ namespace kiwano
|
|||
SetStyle(style);
|
||||
}
|
||||
|
||||
TextActor::~TextActor()
|
||||
{
|
||||
}
|
||||
TextActor::~TextActor() {}
|
||||
|
||||
void TextActor::OnRender(RenderContext& ctx)
|
||||
{
|
||||
|
|
@ -131,4 +129,4 @@ namespace kiwano
|
|||
text_layout_.GetOutlineBrush()->SetColor(outline_color);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -36,8 +36,7 @@ namespace kiwano
|
|||
* \~chinese
|
||||
* @brief 文本角色
|
||||
*/
|
||||
class KGE_API TextActor
|
||||
: public Actor
|
||||
class KGE_API TextActor : public Actor
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -299,5 +298,4 @@ namespace kiwano
|
|||
{
|
||||
text_layout_.SetOutlineStroke(outline_stroke);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -41,9 +41,6 @@ namespace kiwano
|
|||
|
||||
bool Transform::operator==(Transform const& rhs) const
|
||||
{
|
||||
return position == rhs.position &&
|
||||
rotation == rhs.rotation &&
|
||||
scale == rhs.scale &&
|
||||
skew == rhs.skew;
|
||||
}
|
||||
return position == rhs.position && rotation == rhs.rotation && scale == rhs.scale && skew == rhs.skew;
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -44,4 +44,4 @@ namespace kiwano
|
|||
|
||||
bool operator==(const Transform& rhs) const;
|
||||
};
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#include <kiwano/2d/Transition.h>
|
||||
#include <kiwano/2d/Actor.h>
|
||||
#include <kiwano/2d/Stage.h>
|
||||
#include <kiwano/platform/Window.h>
|
||||
#include <kiwano/2d/Transition.h>
|
||||
#include <kiwano/core/Logger.h>
|
||||
#include <kiwano/platform/Window.h>
|
||||
#include <kiwano/render/Renderer.h>
|
||||
|
||||
namespace kiwano
|
||||
|
|
@ -44,9 +44,7 @@ namespace kiwano
|
|||
{
|
||||
}
|
||||
|
||||
Transition::~Transition()
|
||||
{
|
||||
}
|
||||
Transition::~Transition() {}
|
||||
|
||||
bool Transition::IsDone()
|
||||
{
|
||||
|
|
@ -146,27 +144,15 @@ namespace kiwano
|
|||
|
||||
if (process_ < .5f)
|
||||
{
|
||||
out_layer_.SetAreaRect(
|
||||
Rect(
|
||||
window_size_.x * process_,
|
||||
window_size_.y * process_,
|
||||
window_size_.x * (1 - process_),
|
||||
window_size_.y * (1 - process_)
|
||||
)
|
||||
);
|
||||
out_layer_.SetAreaRect(Rect(window_size_.x * process_, window_size_.y * process_,
|
||||
window_size_.x * (1 - process_), window_size_.y * (1 - process_)));
|
||||
}
|
||||
else
|
||||
{
|
||||
out_layer_.SetOpacity(0.f);
|
||||
in_layer_.SetOpacity(1.f);
|
||||
in_layer_.SetAreaRect(
|
||||
Rect(
|
||||
window_size_.x * (1 - process_),
|
||||
window_size_.y * (1 - process_),
|
||||
window_size_.x * process_,
|
||||
window_size_.y * process_
|
||||
)
|
||||
);
|
||||
in_layer_.SetAreaRect(Rect(window_size_.x * (1 - process_), window_size_.y * (1 - process_),
|
||||
window_size_.x * process_, window_size_.y * process_));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -383,4 +369,4 @@ namespace kiwano
|
|||
in_stage_->SetAnchor(Vec2{ 0.f, 0.f });
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -38,8 +38,7 @@ namespace kiwano
|
|||
* \~chinese
|
||||
* @brief 舞台过渡动画
|
||||
*/
|
||||
class KGE_API Transition
|
||||
: public virtual ObjectBase
|
||||
class KGE_API Transition : public virtual ObjectBase
|
||||
{
|
||||
friend class Director;
|
||||
|
||||
|
|
@ -49,9 +48,7 @@ namespace kiwano
|
|||
* @brief 构建空的场景过渡动画
|
||||
* @param duration 动画时长
|
||||
*/
|
||||
explicit Transition(
|
||||
Duration duration
|
||||
);
|
||||
explicit Transition(Duration duration);
|
||||
|
||||
virtual ~Transition();
|
||||
|
||||
|
|
@ -68,10 +65,7 @@ namespace kiwano
|
|||
* @param[in] prev 转出场景
|
||||
* @param[in] next 转入场景
|
||||
*/
|
||||
virtual void Init(
|
||||
StagePtr prev,
|
||||
StagePtr next
|
||||
);
|
||||
virtual void Init(StagePtr prev, StagePtr next);
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
|
|
@ -111,14 +105,12 @@ namespace kiwano
|
|||
LayerArea in_layer_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 淡入淡出过渡动画
|
||||
* @details 前一场景淡出动画结束后,后一场景淡入
|
||||
*/
|
||||
class FadeTransition
|
||||
: public Transition
|
||||
class FadeTransition : public Transition
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
@ -126,27 +118,20 @@ namespace kiwano
|
|||
* @brief 构建淡入淡出过渡动画
|
||||
* @param duration 动画时长
|
||||
*/
|
||||
explicit FadeTransition(
|
||||
Duration duration
|
||||
);
|
||||
explicit FadeTransition(Duration duration);
|
||||
|
||||
protected:
|
||||
void Update(Duration dt) override;
|
||||
|
||||
virtual void Init(
|
||||
StagePtr prev,
|
||||
StagePtr next
|
||||
) override;
|
||||
virtual void Init(StagePtr prev, StagePtr next) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 渐变过渡动画
|
||||
* @details 前一场景淡出动画的同时,后一场景淡入
|
||||
*/
|
||||
class EmergeTransition
|
||||
: public Transition
|
||||
class EmergeTransition : public Transition
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
@ -154,27 +139,20 @@ namespace kiwano
|
|||
* @brief 构建渐变过渡动画
|
||||
* @param duration 动画时长
|
||||
*/
|
||||
explicit EmergeTransition(
|
||||
Duration duration
|
||||
);
|
||||
explicit EmergeTransition(Duration duration);
|
||||
|
||||
protected:
|
||||
void Update(Duration dt) override;
|
||||
|
||||
virtual void Init(
|
||||
StagePtr prev,
|
||||
StagePtr next
|
||||
) override;
|
||||
virtual void Init(StagePtr prev, StagePtr next) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 盒状过渡动画
|
||||
* @details 前一场景以盒状收缩至消失,后一场景以盒状扩大
|
||||
*/
|
||||
class BoxTransition
|
||||
: public Transition
|
||||
class BoxTransition : public Transition
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
@ -182,27 +160,20 @@ namespace kiwano
|
|||
* @brief 构建盒状过渡动画
|
||||
* @param duration 动画时长
|
||||
*/
|
||||
explicit BoxTransition(
|
||||
Duration duration
|
||||
);
|
||||
explicit BoxTransition(Duration duration);
|
||||
|
||||
protected:
|
||||
void Update(Duration dt) override;
|
||||
|
||||
virtual void Init(
|
||||
StagePtr prev,
|
||||
StagePtr next
|
||||
) override;
|
||||
virtual void Init(StagePtr prev, StagePtr next) override;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 位移过渡动画
|
||||
* @details 两场景以位移的方式切换
|
||||
*/
|
||||
class MoveTransition
|
||||
: public Transition
|
||||
class MoveTransition : public Transition
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
@ -223,18 +194,12 @@ namespace kiwano
|
|||
* @param duration 动画时长
|
||||
* @param type 位移方式
|
||||
*/
|
||||
explicit MoveTransition(
|
||||
Duration duration,
|
||||
Type type
|
||||
);
|
||||
explicit MoveTransition(Duration duration, Type type);
|
||||
|
||||
protected:
|
||||
void Update(Duration dt) override;
|
||||
|
||||
virtual void Init(
|
||||
StagePtr prev,
|
||||
StagePtr next
|
||||
) override;
|
||||
virtual void Init(StagePtr prev, StagePtr next) override;
|
||||
|
||||
void Reset() override;
|
||||
|
||||
|
|
@ -244,14 +209,12 @@ namespace kiwano
|
|||
Point start_pos_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 旋转过渡动画
|
||||
* @details 前一场景以旋转方式收缩至消失,后一场景以旋转方式扩大
|
||||
*/
|
||||
class RotationTransition
|
||||
: public Transition
|
||||
class RotationTransition : public Transition
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
|
@ -260,22 +223,16 @@ namespace kiwano
|
|||
* @param duration 动画时长
|
||||
* @param rotation 旋转度数
|
||||
*/
|
||||
explicit RotationTransition(
|
||||
Duration duration,
|
||||
float rotation = 360
|
||||
);
|
||||
explicit RotationTransition(Duration duration, float rotation = 360);
|
||||
|
||||
protected:
|
||||
void Update(Duration dt) override;
|
||||
|
||||
virtual void Init(
|
||||
StagePtr prev,
|
||||
StagePtr next
|
||||
) override;
|
||||
virtual void Init(StagePtr prev, StagePtr next) override;
|
||||
|
||||
void Reset() override;
|
||||
|
||||
private:
|
||||
float rotation_;
|
||||
};
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#include <kiwano/2d/action/Action.h>
|
||||
#include <kiwano/2d/Actor.h>
|
||||
#include <kiwano/2d/action/Action.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -32,13 +32,9 @@ namespace kiwano
|
|||
{
|
||||
}
|
||||
|
||||
Action::~Action()
|
||||
{
|
||||
}
|
||||
Action::~Action() {}
|
||||
|
||||
void Action::Init(Actor* target)
|
||||
{
|
||||
}
|
||||
void Action::Init(Actor* target) {}
|
||||
|
||||
void Action::Update(Actor* target, Duration dt)
|
||||
{
|
||||
|
|
@ -88,8 +84,7 @@ namespace kiwano
|
|||
if (cb_loop_done_)
|
||||
cb_loop_done_(target);
|
||||
|
||||
if (loops_ >= 0
|
||||
&& loops_done_ >= loops_)
|
||||
if (loops_ >= 0 && loops_done_ >= loops_)
|
||||
{
|
||||
Done();
|
||||
}
|
||||
|
|
@ -110,4 +105,4 @@ namespace kiwano
|
|||
Init(target);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@
|
|||
|
||||
#pragma once
|
||||
#include <kiwano/core/Common.h>
|
||||
#include <kiwano/core/Time.h>
|
||||
#include <kiwano/core/SmartPtr.hpp>
|
||||
#include <kiwano/core/ObjectBase.h>
|
||||
#include <kiwano/core/SmartPtr.hpp>
|
||||
#include <kiwano/core/Time.h>
|
||||
#include <kiwano/math/math.h>
|
||||
|
||||
namespace kiwano
|
||||
|
|
@ -192,7 +192,6 @@ namespace kiwano
|
|||
|
||||
/** @} */
|
||||
|
||||
|
||||
inline void Action::Resume()
|
||||
{
|
||||
running_ = true;
|
||||
|
|
@ -287,4 +286,4 @@ namespace kiwano
|
|||
{
|
||||
return cb_loop_done_;
|
||||
}
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -37,4 +37,4 @@ namespace kiwano
|
|||
return new ActionDelay(GetDelay());
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -30,16 +30,13 @@ namespace kiwano
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 延时动画
|
||||
class KGE_API ActionDelay
|
||||
: public Action
|
||||
class KGE_API ActionDelay : public Action
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
/// @brief 构建延时动画
|
||||
/// @param delay 延时时长
|
||||
ActionDelay(
|
||||
Duration delay
|
||||
);
|
||||
ActionDelay(Duration delay);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
|
|
@ -51,4 +48,4 @@ namespace kiwano
|
|||
};
|
||||
|
||||
/** @} */
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#include <kiwano/2d/action/ActionGroup.h>
|
||||
#include <kiwano/2d/Actor.h>
|
||||
#include <kiwano/2d/action/ActionGroup.h>
|
||||
#include <kiwano/core/Logger.h>
|
||||
|
||||
namespace kiwano
|
||||
|
|
@ -39,9 +39,7 @@ namespace kiwano
|
|||
this->Add(actions);
|
||||
}
|
||||
|
||||
ActionGroup::~ActionGroup()
|
||||
{
|
||||
}
|
||||
ActionGroup::~ActionGroup() {}
|
||||
|
||||
void ActionGroup::Init(Actor* target)
|
||||
{
|
||||
|
|
@ -145,4 +143,4 @@ namespace kiwano
|
|||
return group;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -32,8 +32,7 @@ namespace kiwano
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 动画组合
|
||||
class KGE_API ActionGroup
|
||||
: public Action
|
||||
class KGE_API ActionGroup : public Action
|
||||
{
|
||||
public:
|
||||
using ActionList = IntrusiveList<ActionPtr>;
|
||||
|
|
@ -83,6 +82,9 @@ namespace kiwano
|
|||
|
||||
/** @} */
|
||||
|
||||
inline ActionGroup::ActionList const& ActionGroup::GetActions() const { return actions_; }
|
||||
|
||||
inline ActionGroup::ActionList const& ActionGroup::GetActions() const
|
||||
{
|
||||
return actions_;
|
||||
}
|
||||
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano/2d/action/ActionTween.h>
|
||||
#include <kiwano/2d/action/ActionWalk.h>
|
||||
#include <kiwano/2d/action/ActionDelay.h>
|
||||
#include <kiwano/2d/action/ActionGroup.h>
|
||||
#include <kiwano/2d/action/ActionTween.h>
|
||||
#include <kiwano/2d/action/ActionWalk.h>
|
||||
#include <kiwano/2d/action/Animation.h>
|
||||
|
||||
namespace kiwano
|
||||
|
|
@ -40,35 +40,68 @@ namespace kiwano
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 设置循环次数
|
||||
inline ActionHelper& SetLoops(int loops) { core->SetLoops(loops); return (*this); }
|
||||
inline ActionHelper& SetLoops(int loops)
|
||||
{
|
||||
core->SetLoops(loops);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置动画延迟
|
||||
inline ActionHelper& SetDelay(Duration delay) { core->SetDelay(delay); return (*this); }
|
||||
inline ActionHelper& SetDelay(Duration delay)
|
||||
{
|
||||
core->SetDelay(delay);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置动画结束回调函数
|
||||
inline ActionHelper& SetDoneCallback(DoneCallback const& cb) { core->SetDoneCallback(cb); return (*this); }
|
||||
inline ActionHelper& SetDoneCallback(DoneCallback const& cb)
|
||||
{
|
||||
core->SetDoneCallback(cb);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置动画循环结束时的回调函数
|
||||
inline ActionHelper& SetLoopDoneCallback(DoneCallback const& cb) { core->SetLoopDoneCallback(cb); return (*this); }
|
||||
inline ActionHelper& SetLoopDoneCallback(DoneCallback const& cb)
|
||||
{
|
||||
core->SetLoopDoneCallback(cb);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 动画结束时移除目标角色
|
||||
inline ActionHelper& RemoveTargetWhenDone() { core->RemoveTargetWhenDone(); return (*this); }
|
||||
inline ActionHelper& RemoveTargetWhenDone()
|
||||
{
|
||||
core->RemoveTargetWhenDone();
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置名称
|
||||
inline ActionHelper& SetName(String const& name) { core->SetName(name); return (*this); }
|
||||
inline ActionHelper& SetName(String const& name)
|
||||
{
|
||||
core->SetName(name);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取指针
|
||||
inline ActionPtr Get() const { return core; }
|
||||
inline ActionPtr Get() const
|
||||
{
|
||||
return core;
|
||||
}
|
||||
|
||||
inline ActionHelper(ActionPtr core) : core(core) {}
|
||||
inline ActionHelper(ActionPtr core)
|
||||
: core(core)
|
||||
{
|
||||
}
|
||||
|
||||
inline operator ActionPtr() const { return core; }
|
||||
inline operator ActionPtr() const
|
||||
{
|
||||
return core;
|
||||
}
|
||||
|
||||
private:
|
||||
ActionPtr core;
|
||||
|
|
@ -82,45 +115,89 @@ namespace kiwano
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 设置动画持续时长
|
||||
inline TweenHelper& SetDuration(Duration dur) { core->SetDuration(dur); return (*this); }
|
||||
inline TweenHelper& SetDuration(Duration dur)
|
||||
{
|
||||
core->SetDuration(dur);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置循环次数
|
||||
inline TweenHelper& SetLoops(int loops) { core->SetLoops(loops); return (*this); }
|
||||
inline TweenHelper& SetLoops(int loops)
|
||||
{
|
||||
core->SetLoops(loops);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置缓动函数
|
||||
inline TweenHelper& SetEaseFunc(EaseFunc ease) { core->SetEaseFunc(ease); return (*this); }
|
||||
inline TweenHelper& SetEaseFunc(EaseFunc ease)
|
||||
{
|
||||
core->SetEaseFunc(ease);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置动画延迟
|
||||
inline TweenHelper& SetDelay(Duration delay) { core->SetDelay(delay); return (*this); }
|
||||
inline TweenHelper& SetDelay(Duration delay)
|
||||
{
|
||||
core->SetDelay(delay);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置动画结束回调函数
|
||||
inline TweenHelper& SetDoneCallback(DoneCallback const& cb) { core->SetDoneCallback(cb); return (*this); }
|
||||
inline TweenHelper& SetDoneCallback(DoneCallback const& cb)
|
||||
{
|
||||
core->SetDoneCallback(cb);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置动画循环结束时的回调函数
|
||||
inline TweenHelper& SetLoopDoneCallback(DoneCallback const& cb) { core->SetLoopDoneCallback(cb); return (*this); }
|
||||
inline TweenHelper& SetLoopDoneCallback(DoneCallback const& cb)
|
||||
{
|
||||
core->SetLoopDoneCallback(cb);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 动画结束时移除目标角色
|
||||
inline TweenHelper& RemoveTargetWhenDone() { core->RemoveTargetWhenDone(); return (*this); }
|
||||
inline TweenHelper& RemoveTargetWhenDone()
|
||||
{
|
||||
core->RemoveTargetWhenDone();
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置名称
|
||||
inline TweenHelper& SetName(String const& name) { core->SetName(name); return (*this); }
|
||||
inline TweenHelper& SetName(String const& name)
|
||||
{
|
||||
core->SetName(name);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取指针
|
||||
inline ActionTweenPtr Get() const { return core; }
|
||||
inline ActionTweenPtr Get() const
|
||||
{
|
||||
return core;
|
||||
}
|
||||
|
||||
inline TweenHelper(ActionTweenPtr core) : core(core) {}
|
||||
inline TweenHelper(ActionTweenPtr core)
|
||||
: core(core)
|
||||
{
|
||||
}
|
||||
|
||||
inline operator ActionPtr() const { return core; }
|
||||
inline operator ActionPtr() const
|
||||
{
|
||||
return core;
|
||||
}
|
||||
|
||||
inline operator ActionTweenPtr() const { return core; }
|
||||
inline operator ActionTweenPtr() const
|
||||
{
|
||||
return core;
|
||||
}
|
||||
|
||||
private:
|
||||
ActionTweenPtr core;
|
||||
|
|
@ -135,8 +212,7 @@ namespace kiwano
|
|||
/// @brief 构造相对位移动画
|
||||
/// @param duration 动画时长
|
||||
/// @param vector 移动向量
|
||||
static inline TweenHelper
|
||||
MoveBy(Duration dur, Point const& vector)
|
||||
static inline TweenHelper MoveBy(Duration dur, Point const& vector)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionMoveBy(dur, vector));
|
||||
}
|
||||
|
|
@ -145,8 +221,7 @@ namespace kiwano
|
|||
/// @brief 构造位移动画
|
||||
/// @param duration 动画时长
|
||||
/// @param pos 目的坐标
|
||||
static inline TweenHelper
|
||||
MoveTo(Duration dur, Point const& pos)
|
||||
static inline TweenHelper MoveTo(Duration dur, Point const& pos)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionMoveTo(dur, pos));
|
||||
}
|
||||
|
|
@ -157,8 +232,7 @@ namespace kiwano
|
|||
/// @param vec 跳跃位移向量
|
||||
/// @param height 跳跃高度
|
||||
/// @param jumps 跳跃次数
|
||||
static inline TweenHelper
|
||||
JumpBy(Duration duration, Vec2 const& vec, float height, int jumps = 1)
|
||||
static inline TweenHelper JumpBy(Duration duration, Vec2 const& vec, float height, int jumps = 1)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionJumpBy(duration, vec, height, jumps));
|
||||
}
|
||||
|
|
@ -169,8 +243,7 @@ namespace kiwano
|
|||
/// @param pos 目的坐标
|
||||
/// @param height 跳跃高度
|
||||
/// @param jumps 跳跃次数
|
||||
static inline TweenHelper
|
||||
JumpTo(Duration duration, Point const& pos, float height, int jumps = 1)
|
||||
static inline TweenHelper JumpTo(Duration duration, Point const& pos, float height, int jumps = 1)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionJumpTo(duration, pos, height, jumps));
|
||||
}
|
||||
|
|
@ -180,8 +253,7 @@ namespace kiwano
|
|||
/// @param duration 动画时长
|
||||
/// @param scale_x 横向缩放相对变化值
|
||||
/// @param scale_y 纵向缩放相对变化值
|
||||
static inline TweenHelper
|
||||
ScaleBy(Duration dur, float scale_x, float scale_y)
|
||||
static inline TweenHelper ScaleBy(Duration dur, float scale_x, float scale_y)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionScaleBy(dur, scale_x, scale_y));
|
||||
}
|
||||
|
|
@ -191,8 +263,7 @@ namespace kiwano
|
|||
/// @param duration 动画时长
|
||||
/// @param scale_x 横向缩放目标值
|
||||
/// @param scale_y 纵向缩放目标值
|
||||
static inline TweenHelper
|
||||
ScaleTo(Duration dur, float scale_x, float scale_y)
|
||||
static inline TweenHelper ScaleTo(Duration dur, float scale_x, float scale_y)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionScaleTo(dur, scale_x, scale_y));
|
||||
}
|
||||
|
|
@ -201,8 +272,7 @@ namespace kiwano
|
|||
/// @brief 构造透明度渐变动画
|
||||
/// @param duration 动画时长
|
||||
/// @param opacity 目标透明度
|
||||
static inline TweenHelper
|
||||
FadeTo(Duration dur, float opacity)
|
||||
static inline TweenHelper FadeTo(Duration dur, float opacity)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionFadeTo(dur, opacity));
|
||||
}
|
||||
|
|
@ -210,8 +280,7 @@ namespace kiwano
|
|||
/// \~chinese
|
||||
/// @brief 构造淡入动画
|
||||
/// @param duration 动画时长
|
||||
static inline TweenHelper
|
||||
FadeIn(Duration dur)
|
||||
static inline TweenHelper FadeIn(Duration dur)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionFadeIn(dur));
|
||||
}
|
||||
|
|
@ -219,8 +288,7 @@ namespace kiwano
|
|||
/// \~chinese
|
||||
/// @brief 构造淡出动画
|
||||
/// @param duration 动画时长
|
||||
static inline TweenHelper
|
||||
FadeOut(Duration dur)
|
||||
static inline TweenHelper FadeOut(Duration dur)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionFadeOut(dur));
|
||||
}
|
||||
|
|
@ -229,8 +297,7 @@ namespace kiwano
|
|||
/// @brief 构造相对旋转动画
|
||||
/// @param duration 动画时长
|
||||
/// @param rotation 角度相对变化值
|
||||
static inline TweenHelper
|
||||
RotateBy(Duration dur, float rotation)
|
||||
static inline TweenHelper RotateBy(Duration dur, float rotation)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionRotateBy(dur, rotation));
|
||||
}
|
||||
|
|
@ -239,8 +306,7 @@ namespace kiwano
|
|||
/// @brief 构造旋转动画
|
||||
/// @param duration 动画时长
|
||||
/// @param rotation 目标角度
|
||||
static inline TweenHelper
|
||||
RotateTo(Duration dur, float rotation)
|
||||
static inline TweenHelper RotateTo(Duration dur, float rotation)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionRotateTo(dur, rotation));
|
||||
}
|
||||
|
|
@ -252,8 +318,8 @@ namespace kiwano
|
|||
/// @param rotating 是否沿路径切线方向旋转
|
||||
/// @param start 路径起点(百分比)
|
||||
/// @param end 路径终点(百分比)
|
||||
static inline TweenHelper
|
||||
Walk(Duration duration, Geometry const& path, bool rotating = false, float start = 0.f, float end = 1.f)
|
||||
static inline TweenHelper Walk(Duration duration, Geometry const& path, bool rotating = false, float start = 0.f,
|
||||
float end = 1.f)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionWalk(duration, path, rotating, start, end));
|
||||
}
|
||||
|
|
@ -262,8 +328,7 @@ namespace kiwano
|
|||
/// @brief 构建帧动画
|
||||
/// @param duration 动画时长
|
||||
/// @param[in] frame_seq 序列帧
|
||||
static inline TweenHelper
|
||||
Animation(Duration dur, FrameSequencePtr frames)
|
||||
static inline TweenHelper Animation(Duration dur, FrameSequencePtr frames)
|
||||
{
|
||||
return TweenHelper(new kiwano::Animation(dur, frames));
|
||||
}
|
||||
|
|
@ -272,8 +337,7 @@ namespace kiwano
|
|||
/// @brief 构造自定义动画
|
||||
/// @param duration 动画时长
|
||||
/// @param tween_func 动画回调函数
|
||||
static inline TweenHelper
|
||||
Custom(Duration dur, ActionCustom::TweenFunc tween_func)
|
||||
static inline TweenHelper Custom(Duration dur, ActionCustom::TweenFunc tween_func)
|
||||
{
|
||||
return TweenHelper(new kiwano::ActionCustom(dur, tween_func));
|
||||
}
|
||||
|
|
@ -281,8 +345,7 @@ namespace kiwano
|
|||
/// \~chinese
|
||||
/// @brief 构建延时动画
|
||||
/// @param delay 延时时长
|
||||
static inline ActionHelper
|
||||
Delay(Duration delay)
|
||||
static inline ActionHelper Delay(Duration delay)
|
||||
{
|
||||
return ActionHelper(new kiwano::ActionDelay(delay));
|
||||
}
|
||||
|
|
@ -291,8 +354,7 @@ namespace kiwano
|
|||
/// @brief 动画组合
|
||||
/// @param actions 动画集合
|
||||
/// @param sequence 动画按顺序依次执行或同时执行
|
||||
static inline ActionHelper
|
||||
Group(Vector<ActionPtr> const& actions, bool sequence = true)
|
||||
static inline ActionHelper Group(Vector<ActionPtr> const& actions, bool sequence = true)
|
||||
{
|
||||
return ActionHelper(new kiwano::ActionGroup(actions, sequence));
|
||||
}
|
||||
|
|
@ -300,12 +362,11 @@ namespace kiwano
|
|||
/// \~chinese
|
||||
/// @brief 同步动画组合
|
||||
/// @param actions 动画集合
|
||||
static inline ActionHelper
|
||||
Multiple(Vector<ActionPtr> const& actions)
|
||||
static inline ActionHelper Multiple(Vector<ActionPtr> const& actions)
|
||||
{
|
||||
return ActionHelper(new kiwano::ActionGroup(actions, false));
|
||||
}
|
||||
};
|
||||
|
||||
/** @} */
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#include <kiwano/2d/action/ActionManager.h>
|
||||
#include <kiwano/2d/Actor.h>
|
||||
#include <kiwano/2d/action/ActionManager.h>
|
||||
#include <kiwano/core/Logger.h>
|
||||
|
||||
namespace kiwano
|
||||
|
|
@ -107,4 +107,4 @@ namespace kiwano
|
|||
{
|
||||
return actions_;
|
||||
}
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -78,4 +78,4 @@ namespace kiwano
|
|||
};
|
||||
|
||||
/** @} */
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#include <functional>
|
||||
#include <kiwano/2d/action/ActionTween.h>
|
||||
#include <kiwano/2d/Actor.h>
|
||||
#include <kiwano/2d/action/ActionTween.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -28,12 +28,30 @@ namespace kiwano
|
|||
// Ease Functions
|
||||
//-------------------------------------------------------
|
||||
|
||||
inline EaseFunc MakeEaseIn(float rate) { return std::bind(math::EaseIn, std::placeholders::_1, rate); }
|
||||
inline EaseFunc MakeEaseOut(float rate) { return std::bind(math::EaseOut, std::placeholders::_1, rate); }
|
||||
inline EaseFunc MakeEaseInOut(float rate) { return std::bind(math::EaseInOut, std::placeholders::_1, rate); }
|
||||
inline EaseFunc MakeEaseElasticIn(float period) { return std::bind(math::EaseElasticIn, std::placeholders::_1, period); }
|
||||
inline EaseFunc MakeEaseElasticOut(float period) { return std::bind(math::EaseElasticOut, std::placeholders::_1, period); }
|
||||
inline EaseFunc MakeEaseElasticInOut(float period) { return std::bind(math::EaseElasticInOut, std::placeholders::_1, period); }
|
||||
inline EaseFunc MakeEaseIn(float rate)
|
||||
{
|
||||
return std::bind(math::EaseIn, std::placeholders::_1, rate);
|
||||
}
|
||||
inline EaseFunc MakeEaseOut(float rate)
|
||||
{
|
||||
return std::bind(math::EaseOut, std::placeholders::_1, rate);
|
||||
}
|
||||
inline EaseFunc MakeEaseInOut(float rate)
|
||||
{
|
||||
return std::bind(math::EaseInOut, std::placeholders::_1, rate);
|
||||
}
|
||||
inline EaseFunc MakeEaseElasticIn(float period)
|
||||
{
|
||||
return std::bind(math::EaseElasticIn, std::placeholders::_1, period);
|
||||
}
|
||||
inline EaseFunc MakeEaseElasticOut(float period)
|
||||
{
|
||||
return std::bind(math::EaseElasticOut, std::placeholders::_1, period);
|
||||
}
|
||||
inline EaseFunc MakeEaseElasticInOut(float period)
|
||||
{
|
||||
return std::bind(math::EaseElasticInOut, std::placeholders::_1, period);
|
||||
}
|
||||
|
||||
KGE_API EaseFunc Ease::Linear = math::Linear;
|
||||
KGE_API EaseFunc Ease::EaseIn = MakeEaseIn(2.f);
|
||||
|
|
@ -131,7 +149,6 @@ namespace kiwano
|
|||
dur_ = duration;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Move Action
|
||||
//-------------------------------------------------------
|
||||
|
|
@ -188,7 +205,6 @@ namespace kiwano
|
|||
delta_pos_ = end_pos_ - start_pos_;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Jump Action
|
||||
//-------------------------------------------------------
|
||||
|
|
@ -252,7 +268,6 @@ namespace kiwano
|
|||
delta_pos_ = end_pos_ - start_pos_;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Scale Action
|
||||
//-------------------------------------------------------
|
||||
|
|
@ -309,7 +324,6 @@ namespace kiwano
|
|||
delta_y_ = end_scale_y_ - start_scale_y_;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Opacity Action
|
||||
//-------------------------------------------------------
|
||||
|
|
@ -351,7 +365,6 @@ namespace kiwano
|
|||
{
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Rotate Action
|
||||
//-------------------------------------------------------
|
||||
|
|
@ -407,7 +420,6 @@ namespace kiwano
|
|||
delta_val_ = end_val_ - start_val_;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------
|
||||
// ActionCustom
|
||||
//-------------------------------------------------------
|
||||
|
|
@ -435,4 +447,4 @@ namespace kiwano
|
|||
tween_func_(target, percent);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -66,7 +66,6 @@ namespace kiwano
|
|||
static KGE_API EaseFunc SineInOut;
|
||||
};
|
||||
|
||||
|
||||
KGE_DECLARE_SMART_PTR(ActionTween);
|
||||
KGE_DECLARE_SMART_PTR(ActionMoveBy);
|
||||
KGE_DECLARE_SMART_PTR(ActionMoveTo);
|
||||
|
|
@ -81,7 +80,6 @@ namespace kiwano
|
|||
KGE_DECLARE_SMART_PTR(ActionRotateTo);
|
||||
KGE_DECLARE_SMART_PTR(ActionCustom);
|
||||
|
||||
|
||||
/**
|
||||
* \addtogroup Actions
|
||||
* @{
|
||||
|
|
@ -89,8 +87,7 @@ namespace kiwano
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 补间动画
|
||||
class KGE_API ActionTween
|
||||
: public Action
|
||||
class KGE_API ActionTween : public Action
|
||||
{
|
||||
public:
|
||||
ActionTween();
|
||||
|
|
@ -127,11 +124,9 @@ namespace kiwano
|
|||
EaseFunc ease_func_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 相对位移动画
|
||||
class KGE_API ActionMoveBy
|
||||
: public ActionTween
|
||||
class KGE_API ActionMoveBy : public ActionTween
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -160,11 +155,9 @@ namespace kiwano
|
|||
Vec2 delta_pos_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 位移动画
|
||||
class KGE_API ActionMoveTo
|
||||
: public ActionMoveBy
|
||||
class KGE_API ActionMoveTo : public ActionMoveBy
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -193,11 +186,9 @@ namespace kiwano
|
|||
Point end_pos_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 相对跳跃动画
|
||||
class KGE_API ActionJumpBy
|
||||
: public ActionTween
|
||||
class KGE_API ActionJumpBy : public ActionTween
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -230,11 +221,9 @@ namespace kiwano
|
|||
Point prev_pos_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 跳跃动画
|
||||
class KGE_API ActionJumpTo
|
||||
: public ActionJumpBy
|
||||
class KGE_API ActionJumpTo : public ActionJumpBy
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -265,11 +254,9 @@ namespace kiwano
|
|||
Point end_pos_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 相对缩放动画
|
||||
class KGE_API ActionScaleBy
|
||||
: public ActionTween
|
||||
class KGE_API ActionScaleBy : public ActionTween
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -300,11 +287,9 @@ namespace kiwano
|
|||
float delta_y_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 缩放动画
|
||||
class KGE_API ActionScaleTo
|
||||
: public ActionScaleBy
|
||||
class KGE_API ActionScaleTo : public ActionScaleBy
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -335,11 +320,9 @@ namespace kiwano
|
|||
float end_scale_y_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 透明度渐变动画
|
||||
class KGE_API ActionFadeTo
|
||||
: public ActionTween
|
||||
class KGE_API ActionFadeTo : public ActionTween
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -372,11 +355,9 @@ namespace kiwano
|
|||
float end_val_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 淡入动画
|
||||
class KGE_API ActionFadeIn
|
||||
: public ActionFadeTo
|
||||
class KGE_API ActionFadeIn : public ActionFadeTo
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -386,11 +367,9 @@ namespace kiwano
|
|||
explicit ActionFadeIn(Duration duration, EaseFunc func = nullptr);
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 淡出动画
|
||||
class KGE_API ActionFadeOut
|
||||
: public ActionFadeTo
|
||||
class KGE_API ActionFadeOut : public ActionFadeTo
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -400,11 +379,9 @@ namespace kiwano
|
|||
explicit ActionFadeOut(Duration duration, EaseFunc func = nullptr);
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 相对旋转动画
|
||||
class KGE_API ActionRotateBy
|
||||
: public ActionTween
|
||||
class KGE_API ActionRotateBy : public ActionTween
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -432,11 +409,9 @@ namespace kiwano
|
|||
float delta_val_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 旋转动画
|
||||
class KGE_API ActionRotateTo
|
||||
: public ActionRotateBy
|
||||
class KGE_API ActionRotateTo : public ActionRotateBy
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -465,11 +440,9 @@ namespace kiwano
|
|||
float end_val_;
|
||||
};
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 自定义动画
|
||||
class KGE_API ActionCustom
|
||||
: public ActionTween
|
||||
class KGE_API ActionCustom : public ActionTween
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -507,4 +480,4 @@ namespace kiwano
|
|||
|
||||
/** @} */
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#include <kiwano/2d/action/ActionWalk.h>
|
||||
#include <kiwano/2d/Actor.h>
|
||||
#include <kiwano/2d/action/ActionWalk.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -124,4 +124,4 @@ namespace kiwano
|
|||
path_.Clear();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -34,8 +34,7 @@ namespace kiwano
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 路径行走动画
|
||||
class KGE_API ActionWalk
|
||||
: public ActionTween
|
||||
class KGE_API ActionWalk : public ActionTween
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -55,7 +54,8 @@ namespace kiwano
|
|||
/// @param start 路径起点(百分比)
|
||||
/// @param end 路径终点(百分比)
|
||||
/// @param func 动画速度缓动函数
|
||||
ActionWalk(Duration duration, Geometry const& path, bool rotating = false, float start = 0.f, float end = 1.f, EaseFunc func = nullptr);
|
||||
ActionWalk(Duration duration, Geometry const& path, bool rotating = false, float start = 0.f, float end = 1.f,
|
||||
EaseFunc func = nullptr);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取该动画的拷贝对象
|
||||
|
|
@ -130,7 +130,13 @@ namespace kiwano
|
|||
|
||||
/** @} */
|
||||
|
||||
inline Geometry const& ActionWalk::GetPath() const { return path_; }
|
||||
|
||||
inline void ActionWalk::SetPath(Geometry const& path) { path_ = path; }
|
||||
inline Geometry const& ActionWalk::GetPath() const
|
||||
{
|
||||
return path_;
|
||||
}
|
||||
|
||||
inline void ActionWalk::SetPath(Geometry const& path)
|
||||
{
|
||||
path_ = path;
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#include <kiwano/2d/action/Animation.h>
|
||||
#include <kiwano/2d/FrameSequence.h>
|
||||
#include <kiwano/2d/Sprite.h>
|
||||
#include <kiwano/2d/action/Animation.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -36,9 +36,7 @@ namespace kiwano
|
|||
this->SetFrameSequence(frame_seq);
|
||||
}
|
||||
|
||||
Animation::~Animation()
|
||||
{
|
||||
}
|
||||
Animation::~Animation() {}
|
||||
|
||||
FrameSequencePtr Animation::GetFrameSequence() const
|
||||
{
|
||||
|
|
@ -104,4 +102,4 @@ namespace kiwano
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano/2d/action/ActionTween.h>
|
||||
#include <kiwano/2d/FrameSequence.h>
|
||||
#include <kiwano/2d/action/ActionTween.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -33,8 +33,7 @@ namespace kiwano
|
|||
|
||||
/// \~chinese
|
||||
/// @brief 帧动画
|
||||
class KGE_API Animation
|
||||
: public ActionTween
|
||||
class KGE_API Animation : public ActionTween
|
||||
{
|
||||
public:
|
||||
Animation();
|
||||
|
|
@ -75,4 +74,4 @@ namespace kiwano
|
|||
};
|
||||
|
||||
/** @} */
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -34,9 +34,7 @@ namespace kiwano
|
|||
Then(func);
|
||||
}
|
||||
|
||||
AsyncTask::~AsyncTask()
|
||||
{
|
||||
}
|
||||
AsyncTask::~AsyncTask() {}
|
||||
|
||||
void AsyncTask::Start()
|
||||
{
|
||||
|
|
@ -88,4 +86,4 @@ namespace kiwano
|
|||
Release();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -19,10 +19,9 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
|
||||
#include <kiwano/core/ObjectBase.h>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -39,8 +38,7 @@ namespace kiwano
|
|||
/// task->Then(DoSomething);
|
||||
/// task->Start();
|
||||
/// @endcode
|
||||
class AsyncTask
|
||||
: public virtual ObjectBase
|
||||
class AsyncTask : public virtual ObjectBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -50,24 +48,18 @@ namespace kiwano
|
|||
/// \~chinese
|
||||
/// @brief 构造异步任务
|
||||
/// @param func 异步回调函数
|
||||
AsyncTask(
|
||||
AsyncTaskFunc func
|
||||
);
|
||||
AsyncTask(AsyncTaskFunc func);
|
||||
|
||||
virtual ~AsyncTask();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 添加异步任务链
|
||||
AsyncTask& Then(
|
||||
AsyncTaskFunc func
|
||||
);
|
||||
AsyncTask& Then(AsyncTaskFunc func);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置任务执行完成后的回调函数
|
||||
/// @note 该函数在 Kiwano 主线程中执行
|
||||
AsyncTask& SetCallback(
|
||||
AsyncTaskCallback callback
|
||||
);
|
||||
AsyncTask& SetCallback(AsyncTaskCallback callback);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 启动异步任务
|
||||
|
|
@ -84,4 +76,4 @@ namespace kiwano
|
|||
Queue<AsyncTaskFunc> thread_func_queue_;
|
||||
AsyncTaskCallback thread_cb_;
|
||||
};
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -19,18 +19,17 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <queue>
|
||||
#include <stack>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#include <sstream>
|
||||
|
||||
#include <3rd-party/OuterC/oc/oc.h>
|
||||
#include <kiwano/macros.h>
|
||||
#include <kiwano/core/Singleton.h>
|
||||
#include <kiwano/macros.h>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <queue>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <stack>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -96,12 +95,16 @@ namespace kiwano
|
|||
/// @par
|
||||
/// 使用函数封装器可以储存、复制和调用任何可调用目标,示例代码如下:
|
||||
/// @code
|
||||
/// Function<bool(int)> func1 = StaticFunc; // bool StaticFunc(int x);
|
||||
/// Function<bool(int)> func2 = Closure(&t, &T::Func); // bool T::Func(int x);
|
||||
/// Function<bool(int)> func3 = T::StaticFunc; // static bool T::StaticFunc(int x);
|
||||
/// Function<bool(int)> func1 = StaticFunc; // bool
|
||||
/// StaticFunc(int x);
|
||||
/// Function<bool(int)> func2 = Closure(&t, &T::Func); // bool
|
||||
/// T::Func(int x);
|
||||
/// Function<bool(int)> func3 = T::StaticFunc; // static bool
|
||||
/// T::StaticFunc(int x);
|
||||
/// Function<bool(int)> func4 = [](int x) -> bool {}; // Lambda function
|
||||
/// Function<bool(int)> func5 = std::bind(&T::Func, &t); // std::bind
|
||||
/// Function<bool(int)> func5 = Callable(); // Callable objects: struct Callable { bool operator()(int x) {} };
|
||||
/// Function<bool(int)> func5 = Callable(); // Callable
|
||||
/// objects: struct Callable { bool operator()(int x) {} };
|
||||
/// @endcode
|
||||
template <typename _FuncTy>
|
||||
using Function = oc::function<_FuncTy>;
|
||||
|
|
@ -133,7 +136,6 @@ namespace kiwano
|
|||
/// @brief 不可拷贝对象
|
||||
using Noncopyable = oc::noncopyable;
|
||||
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 闭包函数
|
||||
template <typename _Ty, typename _Uty, typename _Ret, typename... _Args>
|
||||
|
|
@ -159,4 +161,4 @@ namespace kiwano
|
|||
{
|
||||
return oc::string_to_wide(str);
|
||||
}
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -53,4 +53,4 @@ namespace kiwano
|
|||
flag_ |= flag;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano/macros.h>
|
||||
#include <kiwano/core/Time.h>
|
||||
#include <kiwano/macros.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -51,13 +51,11 @@ namespace kiwano
|
|||
int flag_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 渲染支持组件
|
||||
*/
|
||||
class KGE_API RenderComponent
|
||||
: public virtual ComponentBase
|
||||
class KGE_API RenderComponent : public virtual ComponentBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -79,13 +77,11 @@ namespace kiwano
|
|||
RenderComponent();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 更新支持组件
|
||||
*/
|
||||
class KGE_API UpdateComponent
|
||||
: public virtual ComponentBase
|
||||
class KGE_API UpdateComponent : public virtual ComponentBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -107,13 +103,11 @@ namespace kiwano
|
|||
UpdateComponent();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 事件支持组件
|
||||
*/
|
||||
class KGE_API EventComponent
|
||||
: public virtual ComponentBase
|
||||
class KGE_API EventComponent : public virtual ComponentBase
|
||||
{
|
||||
public:
|
||||
/// \~chinese
|
||||
|
|
@ -126,5 +120,4 @@ namespace kiwano
|
|||
|
||||
EventComponent();
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
#include <kiwano/core/Director.h>
|
||||
#include <kiwano/2d/Actor.h>
|
||||
#include <kiwano/2d/DebugActor.h>
|
||||
#include <kiwano/2d/Stage.h>
|
||||
#include <kiwano/2d/Transition.h>
|
||||
#include <kiwano/2d/DebugActor.h>
|
||||
#include <kiwano/core/Director.h>
|
||||
#include <kiwano/render/RenderContext.h>
|
||||
|
||||
namespace kiwano
|
||||
|
|
@ -32,9 +32,7 @@ namespace kiwano
|
|||
{
|
||||
}
|
||||
|
||||
Director::~Director()
|
||||
{
|
||||
}
|
||||
Director::~Director() {}
|
||||
|
||||
void Director::EnterStage(StagePtr stage, TransitionPtr transition)
|
||||
{
|
||||
|
|
@ -188,4 +186,4 @@ namespace kiwano
|
|||
debug_actor_->DispatchEvent(evt);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#pragma once
|
||||
#include <kiwano/core/Component.h>
|
||||
#include <kiwano/2d/Actor.h>
|
||||
#include <kiwano/2d/Stage.h>
|
||||
#include <kiwano/2d/Transition.h>
|
||||
#include <kiwano/core/Component.h>
|
||||
|
||||
namespace kiwano
|
||||
{
|
||||
|
|
@ -47,10 +47,7 @@ namespace kiwano
|
|||
* @param[in] stage 舞台
|
||||
* @param[in] transition 过渡动画
|
||||
*/
|
||||
void EnterStage(
|
||||
StagePtr stage,
|
||||
TransitionPtr transition = nullptr
|
||||
);
|
||||
void EnterStage(StagePtr stage, TransitionPtr transition = nullptr);
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
|
|
@ -58,19 +55,14 @@ namespace kiwano
|
|||
* @param[in] stage 舞台
|
||||
* @param[in] transition 过渡动画
|
||||
*/
|
||||
void PushStage(
|
||||
StagePtr stage,
|
||||
TransitionPtr transition = nullptr
|
||||
);
|
||||
void PushStage(StagePtr stage, TransitionPtr transition = nullptr);
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
* @brief 退出当前舞台,并切换到上一个舞台
|
||||
* @param[in] transition 过渡动画
|
||||
*/
|
||||
void PopStage(
|
||||
TransitionPtr transition = nullptr
|
||||
);
|
||||
void PopStage(TransitionPtr transition = nullptr);
|
||||
|
||||
/**
|
||||
* \~chinese
|
||||
|
|
@ -123,4 +115,4 @@ namespace kiwano
|
|||
ActorPtr debug_actor_;
|
||||
TransitionPtr transition_;
|
||||
};
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -168,4 +168,4 @@ namespace kiwano
|
|||
return listeners_;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -59,10 +59,7 @@ namespace kiwano
|
|||
/// @brief 添加监听器
|
||||
/// @tparam _EventTy 事件类型
|
||||
/// @param callback 回调函数
|
||||
template <
|
||||
typename _EventTy,
|
||||
typename = typename std::enable_if<IsEvent<_EventTy>::value, int>::type
|
||||
>
|
||||
template <typename _EventTy, typename = typename std::enable_if<IsEvent<_EventTy>::value, int>::type>
|
||||
EventListener* AddListener(EventListener::Callback callback)
|
||||
{
|
||||
return AddListener(KGE_EVENT(_EventTy), callback);
|
||||
|
|
@ -73,10 +70,7 @@ namespace kiwano
|
|||
/// @tparam _EventTy 事件类型
|
||||
/// @param name 监听器名称
|
||||
/// @param callback 回调函数
|
||||
template <
|
||||
typename _EventTy,
|
||||
typename = typename std::enable_if<IsEvent<_EventTy>::value, int>
|
||||
>
|
||||
template <typename _EventTy, typename = typename std::enable_if<IsEvent<_EventTy>::value, int>>
|
||||
EventListener* AddListener(String const& name, EventListener::Callback callback)
|
||||
{
|
||||
return AddListener(name, KGE_EVENT(_EventTy), callback);
|
||||
|
|
@ -137,4 +131,4 @@ namespace kiwano
|
|||
private:
|
||||
Listeners listeners_;
|
||||
};
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -45,8 +45,6 @@ namespace kiwano
|
|||
SetCallback(callback);
|
||||
}
|
||||
|
||||
EventListener::~EventListener()
|
||||
{
|
||||
}
|
||||
EventListener::~EventListener() {}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
|
|
@ -20,11 +20,11 @@
|
|||
|
||||
#pragma once
|
||||
#include <kiwano/core/Common.h>
|
||||
#include <kiwano/core/SmartPtr.hpp>
|
||||
#include <kiwano/core/ObjectBase.h>
|
||||
#include <kiwano/core/SmartPtr.hpp>
|
||||
#include <kiwano/core/event/Event.h>
|
||||
#include <kiwano/core/event/MouseEvent.h>
|
||||
#include <kiwano/core/event/KeyEvent.h>
|
||||
#include <kiwano/core/event/MouseEvent.h>
|
||||
#include <kiwano/core/event/WindowEvent.h>
|
||||
|
||||
namespace kiwano
|
||||
|
|
@ -70,10 +70,7 @@ namespace kiwano
|
|||
/// @brief 构造监听器
|
||||
/// @tparam _EventTy 事件类型
|
||||
/// @param callback 回调函数
|
||||
template <
|
||||
typename _EventTy,
|
||||
typename = typename std::enable_if<IsEvent<_EventTy>::value, int>::type
|
||||
>
|
||||
template <typename _EventTy, typename = typename std::enable_if<IsEvent<_EventTy>::value, int>::type>
|
||||
inline EventListener(Callback const& callback)
|
||||
: EventListener(KGE_EVENT(_EventTy), callback)
|
||||
{
|
||||
|
|
@ -84,10 +81,7 @@ namespace kiwano
|
|||
/// @tparam _EventTy 事件类型
|
||||
/// @param name 监听器名称
|
||||
/// @param callback 回调函数
|
||||
template <
|
||||
typename _EventTy,
|
||||
typename = typename std::enable_if<IsEvent<_EventTy>::value, int>::type
|
||||
>
|
||||
template <typename _EventTy, typename = typename std::enable_if<IsEvent<_EventTy>::value, int>::type>
|
||||
inline EventListener(String const& name, Callback const& callback)
|
||||
: EventListener(name, KGE_EVENT(_EventTy), callback)
|
||||
{
|
||||
|
|
@ -143,10 +137,7 @@ namespace kiwano
|
|||
/// \~chinese
|
||||
/// @brief 设置监听的事件类型
|
||||
/// @tparam _EventTy 事件类型
|
||||
template <
|
||||
typename _EventTy,
|
||||
typename = typename std::enable_if<IsEvent<_EventTy>::value, int>::type
|
||||
>
|
||||
template <typename _EventTy, typename = typename std::enable_if<IsEvent<_EventTy>::value, int>::type>
|
||||
inline void SetEventType()
|
||||
{
|
||||
SetEventType(KGE_EVENT(_EventTy));
|
||||
|
|
@ -164,7 +155,6 @@ namespace kiwano
|
|||
Callback callback_;
|
||||
};
|
||||
|
||||
|
||||
inline void EventListener::Start()
|
||||
{
|
||||
running_ = true;
|
||||
|
|
@ -229,5 +219,4 @@ namespace kiwano
|
|||
callback_(evt);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace kiwano
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue