diff --git a/projects/kiwano-physics/kiwano-physics.vcxproj b/projects/kiwano-physics/kiwano-physics.vcxproj
index dac0da27..cc69700c 100644
--- a/projects/kiwano-physics/kiwano-physics.vcxproj
+++ b/projects/kiwano-physics/kiwano-physics.vcxproj
@@ -13,7 +13,7 @@
-
+
@@ -24,7 +24,7 @@
-
+
diff --git a/projects/kiwano-physics/kiwano-physics.vcxproj.filters b/projects/kiwano-physics/kiwano-physics.vcxproj.filters
index 2a808fb3..a927a9b3 100644
--- a/projects/kiwano-physics/kiwano-physics.vcxproj.filters
+++ b/projects/kiwano-physics/kiwano-physics.vcxproj.filters
@@ -9,7 +9,7 @@
-
+
@@ -18,6 +18,6 @@
-
+
\ No newline at end of file
diff --git a/projects/kiwano/kiwano.vcxproj b/projects/kiwano/kiwano.vcxproj
index 57b8f114..4ec7a3d1 100644
--- a/projects/kiwano/kiwano.vcxproj
+++ b/projects/kiwano/kiwano.vcxproj
@@ -11,19 +11,21 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -40,22 +42,19 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -65,7 +64,10 @@
+
+
+
@@ -88,7 +90,6 @@
-
@@ -113,21 +114,24 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -148,7 +152,6 @@
-
diff --git a/projects/kiwano/kiwano.vcxproj.filters b/projects/kiwano/kiwano.vcxproj.filters
index 24b70a35..2f48b1a4 100644
--- a/projects/kiwano/kiwano.vcxproj.filters
+++ b/projects/kiwano/kiwano.vcxproj.filters
@@ -16,7 +16,7 @@
{896bdedf-6e82-449b-9b6e-0bc69f3699b1}
-
+
{2e18d99a-e906-499a-9e29-4e0783202644}
@@ -25,13 +25,13 @@
{9314f30d-5742-48b6-94e5-e3b4284106f6}
-
+
{86e2d0f2-a9d0-4456-b6a5-d480228bbf82}
{30333461-e9bc-4709-84bd-ce6e0e1a3079}
-
+
{192a47a9-9df6-4f40-a7d3-888eb00c53ac}
@@ -63,29 +63,23 @@
2d
-
- base
+
+ core
-
- base
+
+ core
-
- base
+
+ core
-
- base
+
+ core
-
- base
+
+ core
-
- base
-
-
- base
-
-
- base
+
+ core
math
@@ -107,27 +101,24 @@
math
-
- base
-
-
- base
+
+ core
-
- base
+
+ core
-
- base
+
+ core
-
- base
+
+ core
2d
-
- base
+
+ core
2d
@@ -162,32 +153,32 @@
2d
-
- core
+
+ common
-
- core
+
+ common
-
- core
+
+ common
-
- core
+
+ common
-
- core
+
+ common
-
- core
+
+ common
-
- core
+
+ common
-
- core
+
+ common
-
- core
+
+ common
2d
@@ -201,17 +192,14 @@
2d\action
-
- base
-
-
- base
+
+ core
math
-
- base
+
+ core
renderer
@@ -282,24 +270,39 @@
math
-
- base\win32
+
+ core\win32
-
- base\win32
+
+ core\win32
utils
-
- utils
-
-
- core
+
+ common
utils
+
+ core
+
+
+ core
+
+
+ platform
+
+
+ core
+
+
+ platform
+
+
+ platform
+
@@ -323,17 +326,17 @@
2d
-
- base
+
+ core
-
- base
+
+ core
-
- base
+
+ core
-
- base
+
+ core
platform
@@ -341,23 +344,20 @@
platform
-
- base
+
+ core
-
- base
+
+ core
-
- base
-
-
- base
+
+ core
2d
-
- base
+
+ core
2d
@@ -401,14 +401,11 @@
2d\action
-
- base
+
+ core
-
- base
-
-
- base
+
+ core
renderer
@@ -464,17 +461,29 @@
renderer
-
- base
+
+ core
utils
-
- utils
-
utils
+
+ core
+
+
+ core
+
+
+ platform
+
+
+ platform
+
+
+ platform
+
\ No newline at end of file
diff --git a/src/kiwano-audio/AudioEngine.cpp b/src/kiwano-audio/AudioEngine.cpp
index 53f2d05b..194b180d 100644
--- a/src/kiwano-audio/AudioEngine.cpp
+++ b/src/kiwano-audio/AudioEngine.cpp
@@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-#include
+#include
#include
#include
diff --git a/src/kiwano-audio/AudioEngine.h b/src/kiwano-audio/AudioEngine.h
index ecc4548b..11187a2a 100644
--- a/src/kiwano-audio/AudioEngine.h
+++ b/src/kiwano-audio/AudioEngine.h
@@ -19,10 +19,11 @@
// THE SOFTWARE.
#pragma once
-#include
-#include
-#include
+#include
+#include
+#include
#include
+#include
namespace kiwano
{
diff --git a/src/kiwano-audio/Sound.cpp b/src/kiwano-audio/Sound.cpp
index d0bda67f..622391fb 100644
--- a/src/kiwano-audio/Sound.cpp
+++ b/src/kiwano-audio/Sound.cpp
@@ -18,8 +18,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-#include
-#include
+#include
+#include
#include
#include
diff --git a/src/kiwano-audio/Sound.h b/src/kiwano-audio/Sound.h
index 42ca5650..e94171a4 100644
--- a/src/kiwano-audio/Sound.h
+++ b/src/kiwano-audio/Sound.h
@@ -19,11 +19,11 @@
// THE SOFTWARE.
#pragma once
-#include
-#include
-#include
-#include
+#include
+#include
+#include
#include
+#include
namespace kiwano
{
diff --git a/src/kiwano-audio/SoundPlayer.h b/src/kiwano-audio/SoundPlayer.h
index f3659a5d..913fe04f 100644
--- a/src/kiwano-audio/SoundPlayer.h
+++ b/src/kiwano-audio/SoundPlayer.h
@@ -19,8 +19,8 @@
// THE SOFTWARE.
#pragma once
-#include
-#include
+#include
+#include
#include
namespace kiwano
diff --git a/src/kiwano-audio/Transcoder.cpp b/src/kiwano-audio/Transcoder.cpp
index 23552f8b..256ebe83 100644
--- a/src/kiwano-audio/Transcoder.cpp
+++ b/src/kiwano-audio/Transcoder.cpp
@@ -23,10 +23,10 @@
#endif
#include
-#include
-#include
-#include
-#include
+#include
+#include
+#include
+#include
#include
#include
#include
diff --git a/src/kiwano-audio/Transcoder.h b/src/kiwano-audio/Transcoder.h
index 7d6d0d78..1ee99cf3 100644
--- a/src/kiwano-audio/Transcoder.h
+++ b/src/kiwano-audio/Transcoder.h
@@ -19,7 +19,7 @@
// THE SOFTWARE.
#pragma once
-#include
+#include
#include
#include
#include
diff --git a/src/kiwano-audio/audio-modules.cpp b/src/kiwano-audio/audio-modules.cpp
index fe4403e9..f140f00d 100644
--- a/src/kiwano-audio/audio-modules.cpp
+++ b/src/kiwano-audio/audio-modules.cpp
@@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-#include
+#include
#include
namespace kiwano
@@ -28,7 +28,7 @@ namespace kiwano
namespace modules
{
XAudio2::XAudio2()
- : xaudio2(nullptr)
+ : xaudio2()
, XAudio2Create(nullptr)
{
const auto xaudio2_dll_names =
@@ -40,16 +40,17 @@ namespace kiwano
for (const auto& name : xaudio2_dll_names)
{
- xaudio2 = LoadLibraryW(name);
- if (xaudio2)
+ if (xaudio2.Load(name))
{
- XAudio2Create = (PFN_XAudio2Create)
- GetProcAddress(xaudio2, "XAudio2Create");
break;
}
}
- if (!xaudio2)
+ if (xaudio2.IsValid())
+ {
+ XAudio2Create = xaudio2.GetProcess(L"XAudio2Create");
+ }
+ else
{
KGE_ERROR_LOG(L"Load xaudio2.dll failed");
throw std::runtime_error("Load xaudio2.dll failed");
@@ -57,8 +58,8 @@ namespace kiwano
}
MediaFoundation::MediaFoundation()
- : mfplat(nullptr)
- , mfreadwrite(nullptr)
+ : mfplat()
+ , mfreadwrite()
, MFStartup(nullptr)
, MFShutdown(nullptr)
, MFCreateMediaType(nullptr)
@@ -67,23 +68,13 @@ namespace kiwano
, MFCreateSourceReaderFromByteStream(nullptr)
, MFCreateMFByteStreamOnStream(nullptr)
{
- mfplat = LoadLibraryW(L"Mfplat.dll");
- if (mfplat)
+ if (mfplat.Load(L"Mfplat.dll"))
{
- MFStartup = (PFN_MFStartup)
- GetProcAddress(mfplat, "MFStartup");
-
- MFShutdown = (PFN_MFShutdown)
- GetProcAddress(mfplat, "MFShutdown");
-
- MFCreateMediaType = (PFN_MFCreateMediaType)
- GetProcAddress(mfplat, "MFCreateMediaType");
-
- MFCreateWaveFormatExFromMFMediaType = (PFN_MFCreateWaveFormatExFromMFMediaType)
- GetProcAddress(mfplat, "MFCreateWaveFormatExFromMFMediaType");
-
- MFCreateMFByteStreamOnStream = (PFN_MFCreateMFByteStreamOnStream)
- GetProcAddress(mfplat, "MFCreateMFByteStreamOnStream");
+ MFStartup = mfplat.GetProcess(L"MFStartup");
+ MFShutdown = mfplat.GetProcess(L"MFShutdown");
+ MFCreateMediaType = mfplat.GetProcess(L"MFCreateMediaType");
+ MFCreateWaveFormatExFromMFMediaType = mfplat.GetProcess(L"MFCreateWaveFormatExFromMFMediaType");
+ MFCreateMFByteStreamOnStream = mfplat.GetProcess(L"MFCreateMFByteStreamOnStream");
}
else
{
@@ -91,14 +82,10 @@ namespace kiwano
throw std::runtime_error("Load Mfplat.dll failed");
}
- mfreadwrite = LoadLibraryW(L"Mfreadwrite.dll");
- if (mfreadwrite)
+ if (mfreadwrite.Load(L"Mfreadwrite.dll"))
{
- MFCreateSourceReaderFromURL = (PFN_MFCreateSourceReaderFromURL)
- GetProcAddress(mfreadwrite, "MFCreateSourceReaderFromURL");
-
- MFCreateSourceReaderFromByteStream = (PFN_MFCreateSourceReaderFromByteStream)
- GetProcAddress(mfreadwrite, "MFCreateSourceReaderFromByteStream");
+ MFCreateSourceReaderFromURL = mfreadwrite.GetProcess(L"MFCreateSourceReaderFromURL");
+ MFCreateSourceReaderFromByteStream = mfreadwrite.GetProcess(L"MFCreateSourceReaderFromByteStream");
}
else
{
diff --git a/src/kiwano-audio/audio-modules.h b/src/kiwano-audio/audio-modules.h
index 689ba0dd..299beb34 100644
--- a/src/kiwano-audio/audio-modules.h
+++ b/src/kiwano-audio/audio-modules.h
@@ -19,6 +19,7 @@
// THE SOFTWARE.
#pragma once
+#include
#include
#include
#include
@@ -32,13 +33,6 @@ namespace kiwano
{
class KGE_API XAudio2
{
- XAudio2();
-
- HMODULE xaudio2;
-
- // XAudio2 functions
- typedef HRESULT(WINAPI* PFN_XAudio2Create)(IXAudio2**, UINT32, XAUDIO2_PROCESSOR);
-
public:
static inline XAudio2& Get()
{
@@ -46,16 +40,29 @@ namespace kiwano
return instance;
}
+ // XAudio2 functions
+ typedef HRESULT(WINAPI* PFN_XAudio2Create)(IXAudio2**, UINT32, XAUDIO2_PROCESSOR);
+
PFN_XAudio2Create XAudio2Create;
+
+ private:
+ XAudio2();
+
+ XAudio2(const XAudio2&) = delete;
+ XAudio2& operator=(const XAudio2&) = delete;
+
+ Library xaudio2;
};
class KGE_API MediaFoundation
{
- MediaFoundation();
-
- HMODULE mfplat;
- HMODULE mfreadwrite;
+ public:
+ static inline MediaFoundation& Get()
+ {
+ static MediaFoundation instance;
+ return instance;
+ }
// MediaFoundation functions
typedef HRESULT(WINAPI* PFN_MFStartup)(ULONG, DWORD);
@@ -66,13 +73,6 @@ namespace kiwano
typedef HRESULT(WINAPI* PFN_MFCreateSourceReaderFromByteStream)(IMFByteStream*, IMFAttributes*, IMFSourceReader**);
typedef HRESULT(WINAPI* PFN_MFCreateMFByteStreamOnStream)(IStream*, IMFByteStream**);
- public:
- static inline MediaFoundation& Get()
- {
- static MediaFoundation instance;
- return instance;
- }
-
PFN_MFStartup MFStartup;
PFN_MFShutdown MFShutdown;
PFN_MFCreateMediaType MFCreateMediaType;
@@ -80,6 +80,15 @@ namespace kiwano
PFN_MFCreateSourceReaderFromURL MFCreateSourceReaderFromURL;
PFN_MFCreateSourceReaderFromByteStream MFCreateSourceReaderFromByteStream;
PFN_MFCreateMFByteStreamOnStream MFCreateMFByteStreamOnStream;
+
+ private:
+ MediaFoundation();
+
+ MediaFoundation(const MediaFoundation&) = delete;
+ MediaFoundation& operator=(const MediaFoundation&) = delete;
+
+ Library mfplat;
+ Library mfreadwrite;
};
}
}
diff --git a/src/kiwano-imgui/ImGuiModule.cpp b/src/kiwano-imgui/ImGuiModule.cpp
index 5ed0034f..f164f2bd 100644
--- a/src/kiwano-imgui/ImGuiModule.cpp
+++ b/src/kiwano-imgui/ImGuiModule.cpp
@@ -1,10 +1,10 @@
// Copyright (C) 2019 Nomango
-#include
-#include
-#include
-#include
-#include
+#include
+#include
+#include
+#include
+#include
#include
#include
#include
diff --git a/src/kiwano-imgui/ImGuiModule.h b/src/kiwano-imgui/ImGuiModule.h
index a047da68..c9069a40 100644
--- a/src/kiwano-imgui/ImGuiModule.h
+++ b/src/kiwano-imgui/ImGuiModule.h
@@ -19,8 +19,8 @@
// THE SOFTWARE.
#pragma once
-#include
-#include
+#include
+#include
namespace kiwano
{
diff --git a/src/kiwano-imgui/imgui_impl_dx11.cpp b/src/kiwano-imgui/imgui_impl_dx11.cpp
index a8f20a45..a8dc29eb 100644
--- a/src/kiwano-imgui/imgui_impl_dx11.cpp
+++ b/src/kiwano-imgui/imgui_impl_dx11.cpp
@@ -1,6 +1,6 @@
// dear imgui: Renderer for Kiwano (DirectX11)
-#include
+#include
#include
// DirectX
diff --git a/src/kiwano-network/HttpClient.cpp b/src/kiwano-network/HttpClient.cpp
index 4822be25..7e7d97cc 100644
--- a/src/kiwano-network/HttpClient.cpp
+++ b/src/kiwano-network/HttpClient.cpp
@@ -25,7 +25,7 @@
#include
#include
-#include
+#include
#include
#include <3rd-party/curl/curl.h> // CURL
@@ -36,7 +36,7 @@ namespace
uint32_t write_data(void* buffer, uint32_t size, uint32_t nmemb, void* userp)
{
- core::string* recv_buffer = (core::string*)userp;
+ common::string* recv_buffer = (common::string*)userp;
uint32_t total = size * nmemb;
// add data to the end of recv_buffer
@@ -46,10 +46,10 @@ namespace
return total;
}
- core::string convert_to_utf8(core::wstring const& str)
+ common::string convert_to_utf8(common::wstring const& str)
{
std::wstring_convert> utf8_conv;
- core::string result;
+ common::string result;
try
{
@@ -63,10 +63,10 @@ namespace
return result;
}
- core::wstring convert_from_utf8(core::string const& str)
+ common::wstring convert_from_utf8(common::string const& str)
{
kiwano::string_convert> utf8_conv;
- core::wstring result;
+ common::wstring result;
try
{
@@ -104,7 +104,7 @@ namespace
}
}
- bool Init(HttpClient* client, Vector const& headers, core::string const& url, core::string* response_data, core::string* response_header, char* error_buffer)
+ bool Init(HttpClient* client, Vector const& headers, common::string const& url, common::string* response_data, common::string* response_header, char* error_buffer)
{
if (!SetOption(CURLOPT_ERRORBUFFER, error_buffer))
return false;
@@ -170,11 +170,11 @@ namespace
public:
static inline bool GetRequest(
HttpClient* client,
- Vector const& headers,
- core::string const& url,
+ Vector const& headers,
+ common::string const& url,
long* response_code,
- core::string* response_data,
- core::string* response_header,
+ common::string* response_data,
+ common::string* response_header,
char* error_buffer)
{
Curl curl;
@@ -185,12 +185,12 @@ namespace
static inline bool PostRequest(
HttpClient* client,
- Vector const& headers,
- core::string const& url,
- core::string const& request_data,
+ Vector const& headers,
+ common::string const& url,
+ common::string const& request_data,
long* response_code,
- core::string* response_data,
- core::string* response_header,
+ common::string* response_data,
+ common::string* response_header,
char* error_buffer)
{
Curl curl;
@@ -203,12 +203,12 @@ namespace
static inline bool PutRequest(
HttpClient* client,
- Vector const& headers,
- core::string const& url,
- core::string const& request_data,
+ Vector const& headers,
+ common::string const& url,
+ common::string const& request_data,
long* response_code,
- core::string* response_data,
- core::string* response_header,
+ common::string* response_data,
+ common::string* response_header,
char* error_buffer)
{
Curl curl;
@@ -221,11 +221,11 @@ namespace
static inline bool DeleteRequest(
HttpClient* client,
- Vector const& headers,
- core::string const& url,
+ Vector const& headers,
+ common::string const& url,
long* response_code,
- core::string* response_data,
- core::string* response_header,
+ common::string* response_data,
+ common::string* response_header,
char* error_buffer)
{
Curl curl;
@@ -307,13 +307,13 @@ namespace kiwano
bool ok = false;
long response_code = 0;
char error_message[256] = { 0 };
- core::string response_header;
- core::string response_data;
+ common::string response_header;
+ common::string response_data;
- core::string url = convert_to_utf8(request->GetUrl());
- core::string data = convert_to_utf8(request->GetData());
+ common::string url = convert_to_utf8(request->GetUrl());
+ common::string data = convert_to_utf8(request->GetData());
- Vector headers;
+ Vector headers;
headers.reserve(request->GetHeaders().size());
for (const auto& pair : request->GetHeaders())
{
diff --git a/src/kiwano-network/HttpClient.h b/src/kiwano-network/HttpClient.h
index 73b52f7a..31e7bf1f 100644
--- a/src/kiwano-network/HttpClient.h
+++ b/src/kiwano-network/HttpClient.h
@@ -19,9 +19,9 @@
// THE SOFTWARE.
#pragma once
-#include
-#include
-#include
+#include
+#include
+#include
#include
#include
@@ -36,39 +36,19 @@ namespace kiwano
KGE_DECLARE_SINGLETON(HttpClient);
public:
- void Send(
- HttpRequestPtr request
- );
+ void Send(HttpRequestPtr request);
- inline void SetTimeoutForConnect(Duration timeout)
- {
- timeout_for_connect_ = timeout;
- }
+ void SetTimeoutForConnect(Duration timeout);
- inline Duration GetTimeoutForConnect() const
- {
- return timeout_for_connect_;
- }
+ Duration GetTimeoutForConnect() const;
- inline void SetTimeoutForRead(Duration timeout)
- {
- timeout_for_read_ = timeout;
- }
+ void SetTimeoutForRead(Duration timeout);
- inline Duration GetTimeoutForRead() const
- {
- return timeout_for_read_;
- }
+ Duration GetTimeoutForRead() const;
- inline void SetSSLVerification(String const& root_certificate_path)
- {
- ssl_verification_ = root_certificate_path;
- }
+ void SetSSLVerification(String const& root_certificate_path);
- inline String const& GetSSLVerification() const
- {
- return ssl_verification_;
- }
+ String const& GetSSLVerification() const;
public:
virtual void SetupComponent() override;
@@ -101,5 +81,37 @@ namespace kiwano
std::condition_variable_any sleep_condition_;
};
+
+
+ inline void HttpClient::SetTimeoutForConnect(Duration timeout)
+ {
+ timeout_for_connect_ = timeout;
+ }
+
+ inline Duration HttpClient::GetTimeoutForConnect() const
+ {
+ return timeout_for_connect_;
+ }
+
+ inline void HttpClient::SetTimeoutForRead(Duration timeout)
+ {
+ timeout_for_read_ = timeout;
+ }
+
+ inline Duration HttpClient::GetTimeoutForRead() const
+ {
+ return timeout_for_read_;
+ }
+
+ inline void HttpClient::SetSSLVerification(String const& root_certificate_path)
+ {
+ ssl_verification_ = root_certificate_path;
+ }
+
+ inline String const& HttpClient::GetSSLVerification() const
+ {
+ return ssl_verification_;
+ }
+
}
}
diff --git a/src/kiwano-network/HttpRequest.cpp b/src/kiwano-network/HttpRequest.cpp
index 0a52f3b4..610df352 100644
--- a/src/kiwano-network/HttpRequest.cpp
+++ b/src/kiwano-network/HttpRequest.cpp
@@ -30,19 +30,5 @@ namespace kiwano
SetHeader(L"Content-Type", L"application/json;charset=UTF-8");
data_ = json.dump();
}
-
- void HttpRequest::SetHeader(String const& field, String const& content)
- {
- auto iter = headers_.find(field);
- if (iter != headers_.end())
- {
- headers_[field] = content;
- }
- else
- {
- headers_.insert(std::make_pair(field, content));
- }
- }
-
}
}
diff --git a/src/kiwano-network/HttpRequest.h b/src/kiwano-network/HttpRequest.h
index 942376fe..716f8240 100644
--- a/src/kiwano-network/HttpRequest.h
+++ b/src/kiwano-network/HttpRequest.h
@@ -19,10 +19,10 @@
// THE SOFTWARE.
#pragma once
-#include
-#include
-#include
-#include
+#include
+#include
+#include
+#include
namespace kiwano
{
@@ -47,35 +47,32 @@ namespace kiwano
Delete
};
- inline HttpRequest() : type_(Type::Unknown) {}
+ HttpRequest();
- inline HttpRequest(Type type) : type_(type) {}
+ HttpRequest(Type type);
- inline void SetUrl(String const& url) { url_ = url; }
+ // 请求地址
+ void SetUrl(String const& url);
+ String const& GetUrl() const;
- inline String const& GetUrl() const { return url_; }
+ // 请求类型
+ void SetType(Type type);
+ Type GetType() const;
- inline void SetType(Type type) { type_ = type; }
+ // 请求数据
+ void SetData(String const& data);
+ void SetJsonData(Json const& json);
+ String const& GetData() const;
- inline Type GetType() const { return type_; }
+ // 请求头
+ void SetHeaders(Map const& headers);
+ void SetHeader(String const& field, String const& content);
+ Map& GetHeaders();
+ String const& GetHeader(String const& header) const;
- inline void SetData(String const& data) { data_ = data; }
-
- void SetJsonData(Json const& json);
-
- inline String const& GetData() const { return data_; }
-
- inline void SetHeaders(Map const& headers) { headers_ = headers; }
-
- void SetHeader(String const& field, String const& content);
-
- inline Map& GetHeaders() { return headers_; }
-
- inline String const& GetHeader(String const& header) const { return headers_.at(header); }
-
- inline void SetResponseCallback(ResponseCallback const& callback) { response_cb_ = callback; }
-
- inline ResponseCallback const& GetResponseCallback() const { return response_cb_; }
+ // 响应回调
+ void SetResponseCallback(ResponseCallback const& callback);
+ ResponseCallback const& GetResponseCallback() const;
protected:
Type type_;
@@ -84,5 +81,33 @@ namespace kiwano
Map headers_;
ResponseCallback response_cb_;
};
+
+ inline HttpRequest::HttpRequest() : type_(Type::Unknown) {}
+
+ inline HttpRequest::HttpRequest(Type type) : type_(type) {}
+
+ inline void HttpRequest::SetUrl(String const& url) { url_ = url; }
+
+ inline String const& HttpRequest::GetUrl() const { return url_; }
+
+ inline void HttpRequest::SetType(Type type) { type_ = type; }
+
+ inline HttpRequest::Type HttpRequest::GetType() const { return type_; }
+
+ inline void HttpRequest::SetData(String const& data) { data_ = data; }
+
+ inline String const& HttpRequest::GetData() const { return data_; }
+
+ inline void HttpRequest::SetHeaders(Map const& headers) { headers_ = headers; }
+
+ inline void HttpRequest::SetHeader(String const& field, String const& content) { headers_[field] = content; }
+
+ inline Map& 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_; }
}
}
diff --git a/src/kiwano-network/HttpResponse.hpp b/src/kiwano-network/HttpResponse.hpp
index 24874db9..a2d043b0 100644
--- a/src/kiwano-network/HttpResponse.hpp
+++ b/src/kiwano-network/HttpResponse.hpp
@@ -31,29 +31,30 @@ namespace kiwano
: public ObjectBase
{
public:
- inline HttpResponse(HttpRequestPtr request) : request_(request), succeed_(false), response_code_(0) {}
+ HttpResponse(HttpRequestPtr request);
- inline HttpRequestPtr GetRequest() const { return request_; }
+ // 获取请求
+ HttpRequestPtr GetRequest() const;
- inline void SetSucceed(bool succeed) { succeed_ = succeed; }
+ // 响应状态
+ bool IsSucceed() const;
+ void SetSucceed(bool succeed);
- inline bool IsSucceed() const { return succeed_; }
+ // 响应状态码
+ long GetResponseCode() const;
+ void SetResponseCode(long response_code);
- inline void SetResponseCode(long response_code) { response_code_ = response_code; }
+ // 响应头
+ String GetHeader() const;
+ void SetHeader(String const& response_header);
- inline long GetResponseCode() const { return response_code_; }
+ // 响应数据
+ String const& GetData() const;
+ void SetData(String const& response_data);
- inline void SetHeader(String const& response_header) { response_header_ = response_header; }
-
- inline String GetHeader() const { return response_header_; }
-
- inline void SetData(String const& response_data) { response_data_ = response_data; }
-
- inline String const& GetData() const { return response_data_; }
-
- inline void SetError(String const& error_buffer) { error_buffer_ = error_buffer; }
-
- inline String const& GetError() const { return error_buffer_; }
+ // 错误信息
+ String const& GetError() const;
+ void SetError(String const& error_buffer);
protected:
bool succeed_;
@@ -64,5 +65,29 @@ namespace kiwano
String response_data_;
String error_buffer_;
};
+
+ inline HttpResponse::HttpResponse(HttpRequestPtr request) : request_(request), succeed_(false), response_code_(0) {}
+
+ inline HttpRequestPtr HttpResponse::GetRequest() const { return request_; }
+
+ inline void HttpResponse::SetSucceed(bool succeed) { succeed_ = succeed; }
+
+ inline bool HttpResponse::IsSucceed() const { return succeed_; }
+
+ inline void HttpResponse::SetResponseCode(long response_code) { response_code_ = response_code; }
+
+ inline long HttpResponse::GetResponseCode() const { return response_code_; }
+
+ inline void HttpResponse::SetHeader(String const& response_header) { response_header_ = response_header; }
+
+ inline String HttpResponse::GetHeader() const { return response_header_; }
+
+ inline void HttpResponse::SetData(String const& response_data) { response_data_ = response_data; }
+
+ inline String const& HttpResponse::GetData() const { return response_data_; }
+
+ inline void HttpResponse::SetError(String const& error_buffer) { error_buffer_ = error_buffer; }
+
+ inline String const& HttpResponse::GetError() const { return error_buffer_; }
}
}
diff --git a/src/kiwano-physics/Body.cpp b/src/kiwano-physics/Body.cpp
index 18feed30..379b40f1 100644
--- a/src/kiwano-physics/Body.cpp
+++ b/src/kiwano-physics/Body.cpp
@@ -26,7 +26,7 @@ namespace kiwano
namespace physics
{
- PhysicBody::PhysicBody()
+ Body::Body()
: body_(nullptr)
, actor_(nullptr)
, world_(nullptr)
@@ -36,25 +36,25 @@ namespace kiwano
{
}
- PhysicBody::PhysicBody(b2Body* body, Actor* actor)
- : PhysicBody()
+ Body::Body(b2Body* body, Actor* actor)
+ : Body()
{
SetB2Body(body);
SetActor(actor);
}
- PhysicBody::PhysicBody(PhysicWorld* world, Actor* actor)
- : PhysicBody()
+ Body::Body(World* world, Actor* actor)
+ : Body()
{
Init(world, actor);
}
- PhysicBody::~PhysicBody()
+ Body::~Body()
{
Destroy();
}
- void PhysicBody::Init(PhysicWorld* world, Actor* actor)
+ void Body::Init(World* world, Actor* actor)
{
KGE_ASSERT(world);
@@ -69,38 +69,38 @@ namespace kiwano
UpdateFromActor();
}
- PhysicFixture PhysicBody::AddFixture(PhysicShape* shape, const PhysicFixture::Param& param)
+ Fixture Body::AddFixture(Shape* shape, const Fixture::Param& param)
{
KGE_ASSERT(body_ && world_);
- return PhysicFixture(this, shape, param);
+ return Fixture(this, shape, param);
}
- PhysicFixture PhysicBody::AddCircleShape(float radius, float density)
+ Fixture Body::AddCircleShape(float radius, float density)
{
- return AddFixture(&PhysicCircleShape(radius), PhysicFixture::Param(density));
+ return AddFixture(&CircleShape(radius), Fixture::Param(density));
}
- PhysicFixture PhysicBody::AddBoxShape(Vec2 const& size, float density)
+ Fixture Body::AddBoxShape(Vec2 const& size, float density)
{
- return AddFixture(&PhysicBoxShape(size), PhysicFixture::Param(density));
+ return AddFixture(&BoxShape(size), Fixture::Param(density));
}
- PhysicFixture PhysicBody::AddPolygonShape(Vector const& vertexs, float density)
+ Fixture Body::AddPolygonShape(Vector const& vertexs, float density)
{
- return AddFixture(&PhysicPolygonShape(vertexs), PhysicFixture::Param(density));
+ return AddFixture(&PolygonShape(vertexs), Fixture::Param(density));
}
- PhysicFixture PhysicBody::AddEdgeShape(Point const& p1, Point const& p2, float density)
+ Fixture Body::AddEdgeShape(Point const& p1, Point const& p2, float density)
{
- return AddFixture(&PhysicEdgeShape(p1, p2), PhysicFixture::Param(density));
+ return AddFixture(&EdgeShape(p1, p2), Fixture::Param(density));
}
- PhysicFixture PhysicBody::AddChainShape(Vector const& vertexs, bool loop, float density)
+ Fixture Body::AddChainShape(Vector const& vertexs, bool loop, float density)
{
- return AddFixture(&PhysicChainShape(vertexs, loop), PhysicFixture::Param(density));
+ return AddFixture(&ChainShape(vertexs, loop), Fixture::Param(density));
}
- void PhysicBody::RemoveFixture(PhysicFixture const& fixture)
+ void Body::RemoveFixture(Fixture const& fixture)
{
if (fixture.GetB2Fixture())
{
@@ -109,7 +109,7 @@ namespace kiwano
}
}
- void PhysicBody::SetCategoryBits(uint16_t category_bits)
+ void Body::SetCategoryBits(uint16_t category_bits)
{
KGE_ASSERT(body_);
@@ -126,7 +126,7 @@ namespace kiwano
}
}
- void PhysicBody::SetMaskBits(uint16_t mask_bits)
+ void Body::SetMaskBits(uint16_t mask_bits)
{
KGE_ASSERT(body_);
@@ -143,7 +143,7 @@ namespace kiwano
}
}
- void PhysicBody::SetGroupIndex(int16_t index)
+ void Body::SetGroupIndex(int16_t index)
{
KGE_ASSERT(body_);
@@ -160,7 +160,7 @@ namespace kiwano
}
}
- void PhysicBody::GetMassData(float* mass, Point* center, float* inertia) const
+ void Body::GetMassData(float* mass, Point* center, float* inertia) const
{
KGE_ASSERT(body_ && world_);
@@ -172,7 +172,7 @@ namespace kiwano
if (inertia) *inertia = data.I;
}
- void PhysicBody::SetMassData(float mass, Point const& center, float inertia)
+ void Body::SetMassData(float mass, Point const& center, float inertia)
{
KGE_ASSERT(body_ && world_);
@@ -183,67 +183,67 @@ namespace kiwano
body_->SetMassData(&data);
}
- void PhysicBody::ResetMassData()
+ void Body::ResetMassData()
{
KGE_ASSERT(body_);
body_->ResetMassData();
}
- Point PhysicBody::GetBodyPosition() const
+ Point Body::GetBodyPosition() const
{
KGE_ASSERT(body_ && world_);
return world_->World2Stage(body_->GetPosition());
}
- void PhysicBody::SetBodyTransform(Point const& pos, float angle)
+ void Body::SetBodyTransform(Point const& pos, float angle)
{
KGE_ASSERT(body_ && world_);
body_->SetTransform(world_->Stage2World(pos), math::Degree2Radian(angle));
}
- Point PhysicBody::GetLocalPoint(Point const& world) const
+ Point Body::GetLocalPoint(Point const& world) const
{
KGE_ASSERT(body_ && world_);
return world_->World2Stage(body_->GetLocalPoint(world_->Stage2World(world)));
}
- Point PhysicBody::GetWorldPoint(Point const& local) const
+ Point Body::GetWorldPoint(Point const& local) const
{
KGE_ASSERT(body_ && world_);
return world_->World2Stage(body_->GetWorldPoint(world_->Stage2World(local)));
}
- Point PhysicBody::GetLocalCenter() const
+ Point Body::GetLocalCenter() const
{
KGE_ASSERT(body_ && world_);
return world_->World2Stage(body_->GetLocalCenter());
}
- Point PhysicBody::GetWorldCenter() const
+ Point Body::GetWorldCenter() const
{
KGE_ASSERT(body_ && world_);
return world_->World2Stage(body_->GetWorldCenter());
}
- void PhysicBody::ApplyForce(Vec2 const& force, Point const& point, bool wake)
+ void Body::ApplyForce(Vec2 const& force, Point const& point, bool wake)
{
KGE_ASSERT(body_ && world_);
body_->ApplyForce(b2Vec2(force.x, force.y), world_->Stage2World(point), wake);
}
- void PhysicBody::ApplyForceToCenter(Vec2 const& force, bool wake)
+ void Body::ApplyForceToCenter(Vec2 const& force, bool wake)
{
KGE_ASSERT(body_ && world_);
body_->ApplyForceToCenter(b2Vec2(force.x, force.y), wake);
}
- void PhysicBody::ApplyTorque(float torque, bool wake)
+ void Body::ApplyTorque(float torque, bool wake)
{
KGE_ASSERT(body_ && world_);
body_->ApplyTorque(torque, wake);
}
- void PhysicBody::SetB2Body(b2Body* body)
+ void Body::SetB2Body(b2Body* body)
{
body_ = body;
if (body_)
@@ -252,7 +252,7 @@ namespace kiwano
}
}
- void PhysicBody::Destroy()
+ void Body::Destroy()
{
if (world_)
{
@@ -264,7 +264,7 @@ namespace kiwano
actor_ = nullptr;
}
- void PhysicBody::UpdateActor()
+ void Body::UpdateActor()
{
if (actor_ && body_)
{
@@ -280,7 +280,7 @@ namespace kiwano
}
}
- void PhysicBody::UpdateFromActor()
+ void Body::UpdateFromActor()
{
if (actor_ && body_)
{
@@ -301,7 +301,7 @@ namespace kiwano
}
}
- void PhysicBody::UpdateFixtureFilter(b2Fixture* fixture)
+ void Body::UpdateFixtureFilter(b2Fixture* fixture)
{
b2Filter filter;
filter.categoryBits = category_bits_;
diff --git a/src/kiwano-physics/Body.h b/src/kiwano-physics/Body.h
index 8647eddf..e9f25989 100644
--- a/src/kiwano-physics/Body.h
+++ b/src/kiwano-physics/Body.h
@@ -28,11 +28,11 @@ namespace kiwano
{
namespace physics
{
- class PhysicWorld;
+ class World;
// 物体
- KGE_DECLARE_SMART_PTR(PhysicBody);
- class KGE_API PhysicBody
+ KGE_DECLARE_SMART_PTR(Body);
+ class KGE_API Body
: public virtual RefCounter
{
public:
@@ -43,33 +43,33 @@ namespace kiwano
Dynamic,
};
- PhysicBody();
- PhysicBody(b2Body* body, Actor* actor);
- PhysicBody(PhysicWorld* world, Actor* actor);
- PhysicBody(PhysicWorld* world, ActorPtr actor) : PhysicBody(world, actor.get()) {}
- virtual ~PhysicBody();
+ Body();
+ Body(b2Body* body, Actor* actor);
+ Body(World* world, Actor* actor);
+ Body(World* world, ActorPtr actor) : Body(world, actor.get()) {}
+ virtual ~Body();
// 初始化
- void Init(PhysicWorld* world, Actor* actor);
+ void Init(World* world, Actor* actor);
// 添加夹具
- PhysicFixture AddFixture(PhysicShape* shape, const PhysicFixture::Param& param);
+ Fixture AddFixture(Shape* shape, const Fixture::Param& param);
// 添加形状
- PhysicFixture AddCircleShape(float radius, float density = 0.f);
- PhysicFixture AddBoxShape(Vec2 const& size, float density = 0.f);
- PhysicFixture AddPolygonShape(Vector const& vertexs, float density = 0.f);
- PhysicFixture AddEdgeShape(Point const& p1, Point const& p2, float density = 0.f);
- PhysicFixture AddChainShape(Vector const& vertexs, bool loop, float density = 0.f);
+ Fixture AddCircleShape(float radius, float density = 0.f);
+ Fixture AddBoxShape(Vec2 const& size, float density = 0.f);
+ Fixture AddPolygonShape(Vector const& vertexs, float density = 0.f);
+ Fixture AddEdgeShape(Point const& p1, Point const& p2, float density = 0.f);
+ Fixture AddChainShape(Vector const& vertexs, bool loop, float density = 0.f);
// 获取夹具
- PhysicFixture GetFixtureList() const { KGE_ASSERT(body_); return PhysicFixture(body_->GetFixtureList()); }
+ Fixture GetFixtureList() const { KGE_ASSERT(body_); return Fixture(body_->GetFixtureList()); }
// 移除夹具
- void RemoveFixture(PhysicFixture const& fixture);
+ void RemoveFixture(Fixture const& fixture);
// 获取接触边
- PhysicContactEdge GetContactList() const { KGE_ASSERT(body_); PhysicContactEdge(body_->GetContactList()); }
+ ContactEdge GetContactList() const { KGE_ASSERT(body_); ContactEdge(body_->GetContactList()); }
// 类别码
uint16_t GetCategoryBits() const { return category_bits_; }
@@ -153,8 +153,8 @@ namespace kiwano
const b2Body* GetB2Body() const { return body_; }
void SetB2Body(b2Body* body);
- PhysicWorld* GetWorld() { return world_; }
- const PhysicWorld* GetWorld() const { return world_; }
+ World* GetWorld() { return world_; }
+ const World* GetWorld() const { return world_; }
void Destroy();
@@ -166,7 +166,7 @@ namespace kiwano
protected:
Actor* actor_;
- PhysicWorld* world_;
+ World* world_;
b2Body* body_;
uint16_t category_bits_;
diff --git a/src/kiwano-physics/Contact.cpp b/src/kiwano-physics/Contact.cpp
index 8b5bcf41..b46698ce 100644
--- a/src/kiwano-physics/Contact.cpp
+++ b/src/kiwano-physics/Contact.cpp
@@ -27,87 +27,87 @@ namespace kiwano
namespace physics
{
- PhysicContact::PhysicContact()
+ Contact::Contact()
: contact_(nullptr)
{
}
- PhysicContact::PhysicContact(b2Contact* contact)
- : PhysicContact()
+ Contact::Contact(b2Contact* contact)
+ : Contact()
{
SetB2Contact(contact);
}
- PhysicContact PhysicContact::GetNext()
+ Contact Contact::GetNext()
{
KGE_ASSERT(contact_);
- return PhysicContact(contact_->GetNext());
+ return Contact(contact_->GetNext());
}
- const PhysicContact PhysicContact::GetNext() const
+ const Contact Contact::GetNext() const
{
KGE_ASSERT(contact_);
- return PhysicContact(contact_->GetNext());
+ return Contact(contact_->GetNext());
}
- PhysicFixture PhysicContact::GetFixtureA()
+ Fixture Contact::GetFixtureA()
{
KGE_ASSERT(contact_);
- return PhysicFixture(contact_->GetFixtureA());
+ return Fixture(contact_->GetFixtureA());
}
- const PhysicFixture PhysicContact::GetFixtureA() const
+ const Fixture Contact::GetFixtureA() const
{
KGE_ASSERT(contact_);
- return PhysicFixture(contact_->GetFixtureA());
+ return Fixture(contact_->GetFixtureA());
}
- PhysicFixture PhysicContact::GetFixtureB()
+ Fixture Contact::GetFixtureB()
{
KGE_ASSERT(contact_);
- return PhysicFixture(contact_->GetFixtureB());
+ return Fixture(contact_->GetFixtureB());
}
- const PhysicFixture PhysicContact::GetFixtureB() const
+ const Fixture Contact::GetFixtureB() const
{
KGE_ASSERT(contact_);
- return PhysicFixture(contact_->GetFixtureB());
+ return Fixture(contact_->GetFixtureB());
}
- void PhysicContact::SetTangentSpeed(float speed)
+ void Contact::SetTangentSpeed(float speed)
{
KGE_ASSERT(contact_);
- PhysicBody* body = GetFixtureA().GetBody();
+ Body* body = GetFixtureA().GetBody();
KGE_ASSERT(body);
- PhysicWorld* world = body->GetWorld();
+ World* world = body->GetWorld();
KGE_ASSERT(world);
contact_->SetTangentSpeed(world->Stage2World(speed));
}
- float PhysicContact::GetTangentSpeed() const
+ float Contact::GetTangentSpeed() const
{
KGE_ASSERT(contact_);
- const PhysicBody* body = GetFixtureA().GetBody();
+ const Body* body = GetFixtureA().GetBody();
KGE_ASSERT(body);
- const PhysicWorld* world = body->GetWorld();
+ const World* world = body->GetWorld();
KGE_ASSERT(world);
return world->World2Stage(contact_->GetTangentSpeed());
}
- PhysicContactEdge::PhysicContactEdge()
+ ContactEdge::ContactEdge()
: edge_(nullptr)
{
}
- PhysicContactEdge::PhysicContactEdge(b2ContactEdge* edge)
- : PhysicContactEdge()
+ ContactEdge::ContactEdge(b2ContactEdge* edge)
+ : ContactEdge()
{
SetB2ContactEdge(edge);
}
diff --git a/src/kiwano-physics/Contact.h b/src/kiwano-physics/Contact.h
index b32b8db4..0f0ee915 100644
--- a/src/kiwano-physics/Contact.h
+++ b/src/kiwano-physics/Contact.h
@@ -26,14 +26,14 @@ namespace kiwano
{
namespace physics
{
- class PhysicBody;
+ class Body;
// 接触
- class KGE_API PhysicContact
+ class KGE_API Contact
{
public:
- PhysicContact();
- PhysicContact(b2Contact* contact);
+ Contact();
+ Contact(b2Contact* contact);
// 是否是接触
bool IsTouching() const { KGE_ASSERT(contact_); return contact_->IsTouching(); }
@@ -43,16 +43,16 @@ namespace kiwano
bool IsEnabled() const { KGE_ASSERT(contact_); return contact_->IsEnabled(); }
// 获取下一接触
- PhysicContact GetNext();
- const PhysicContact GetNext() const;
+ Contact GetNext();
+ const Contact GetNext() const;
// 夹具 A
- PhysicFixture GetFixtureA();
- const PhysicFixture GetFixtureA() const;
+ Fixture GetFixtureA();
+ const Fixture GetFixtureA() const;
// 夹具 B
- PhysicFixture GetFixtureB();
- const PhysicFixture GetFixtureB() const;
+ Fixture GetFixtureB();
+ const Fixture GetFixtureB() const;
// 摩擦
void SetFriction(float friction) { KGE_ASSERT(contact_); contact_->SetFriction(friction); }
@@ -78,27 +78,27 @@ namespace kiwano
// 接触边
- class KGE_API PhysicContactEdge
+ class KGE_API ContactEdge
{
public:
- PhysicContactEdge();
- PhysicContactEdge(b2ContactEdge* edge);
+ ContactEdge();
+ ContactEdge(b2ContactEdge* edge);
// 获取接触物体
- PhysicBody* GetOtherBody() { KGE_ASSERT(edge_); return static_cast(edge_->other->GetUserData()); }
- const PhysicBody* GetOtherBody() const { KGE_ASSERT(edge_); return static_cast(edge_->other->GetUserData()); }
+ Body* GetOtherBody() { KGE_ASSERT(edge_); return static_cast(edge_->other->GetUserData()); }
+ const Body* GetOtherBody() const { KGE_ASSERT(edge_); return static_cast(edge_->other->GetUserData()); }
// 获取接触
- PhysicContact GetContact() { KGE_ASSERT(edge_); return PhysicContact(edge_->contact); }
- const PhysicContact GetContact() const { KGE_ASSERT(edge_); return PhysicContact(edge_->contact); }
+ Contact GetContact() { KGE_ASSERT(edge_); return Contact(edge_->contact); }
+ const Contact GetContact() const { KGE_ASSERT(edge_); return Contact(edge_->contact); }
// 获取上一接触边
- PhysicContactEdge GetPrev() { KGE_ASSERT(edge_); return PhysicContactEdge(edge_->prev); }
- const PhysicContactEdge GetPrev() const { KGE_ASSERT(edge_); return PhysicContactEdge(edge_->prev); }
+ ContactEdge GetPrev() { KGE_ASSERT(edge_); return ContactEdge(edge_->prev); }
+ const ContactEdge GetPrev() const { KGE_ASSERT(edge_); return ContactEdge(edge_->prev); }
// 获取下一接触边
- PhysicContactEdge GetNext() { KGE_ASSERT(edge_); return PhysicContactEdge(edge_->next); }
- const PhysicContactEdge GetNext() const { KGE_ASSERT(edge_); return PhysicContactEdge(edge_->next); }
+ ContactEdge GetNext() { KGE_ASSERT(edge_); return ContactEdge(edge_->next); }
+ const ContactEdge GetNext() const { KGE_ASSERT(edge_); return ContactEdge(edge_->next); }
b2ContactEdge* GetB2ContactEdge() { return edge_; }
const b2ContactEdge* GetB2ContactEdge() const { return edge_; }
diff --git a/src/kiwano-physics/ContactEvent.cpp b/src/kiwano-physics/ContactEvent.cpp
new file mode 100644
index 00000000..108134a7
--- /dev/null
+++ b/src/kiwano-physics/ContactEvent.cpp
@@ -0,0 +1,65 @@
+// Copyright (c) 2018-2019 Kiwano - Nomango
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#include
+
+namespace kiwano
+{
+ namespace event
+ {
+ EventType event::ContactBegin = EventType(L"ContactBegin");
+ EventType event::ContactEnd = EventType(L"ContactEnd");
+ }
+
+ namespace physics
+ {
+
+ ContactBeginEvent::ContactBeginEvent()
+ : Event(event::ContactBegin)
+ , body_a(nullptr)
+ , body_b(nullptr)
+ {
+ }
+
+ ContactBeginEvent::ContactBeginEvent(Contact const& contact)
+ : ContactBeginEvent()
+ {
+ this->contact = contact;
+ body_a = this->contact.GetFixtureA().GetBody();
+ body_b = this->contact.GetFixtureB().GetBody();
+ }
+
+ ContactEndEvent::ContactEndEvent()
+ : Event(event::ContactEnd)
+ , body_a(nullptr)
+ , body_b(nullptr)
+ {
+ }
+
+ ContactEndEvent::ContactEndEvent(Contact const& contact)
+ : ContactEndEvent()
+ {
+ this->contact = contact;
+ body_a = this->contact.GetFixtureA().GetBody();
+ body_b = this->contact.GetFixtureB().GetBody();
+ }
+
+}
+}
diff --git a/src/kiwano-physics/ContactEvent.h b/src/kiwano-physics/ContactEvent.h
new file mode 100644
index 00000000..ba2488f4
--- /dev/null
+++ b/src/kiwano-physics/ContactEvent.h
@@ -0,0 +1,62 @@
+// Copyright (c) 2018-2019 Kiwano - Nomango
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#pragma once
+#include
+#include
+
+namespace kiwano
+{
+ namespace physics
+ {
+ // 接触开始事件
+ class KGE_API ContactBeginEvent
+ : public Event
+ {
+ public:
+ Contact contact;
+ Body* body_a;
+ Body* body_b;
+
+ ContactBeginEvent();
+ ContactBeginEvent(Contact const& contact);
+ };
+
+ // 接触结束事件
+ class KGE_API ContactEndEvent
+ : public Event
+ {
+ public:
+ Contact contact;
+ Body* body_a;
+ Body* body_b;
+
+ ContactEndEvent();
+ ContactEndEvent(Contact const& contact);
+ };
+
+ }
+
+ namespace event
+ {
+ extern EventType ContactBegin; // 接触开始
+ extern EventType ContactEnd; // 接触结束
+ }
+}
diff --git a/src/kiwano-physics/ContactListener.cpp b/src/kiwano-physics/ContactListener.cpp
deleted file mode 100644
index 276d5a78..00000000
--- a/src/kiwano-physics/ContactListener.cpp
+++ /dev/null
@@ -1,158 +0,0 @@
-// Copyright (c) 2018-2019 Kiwano - Nomango
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-#include
-#include
-#include
-
-namespace kiwano
-{
- namespace physics
- {
- PhysicContactListener::PhysicContactListener()
- : running_(true)
- {
- }
-
- PhysicContactListener::~PhysicContactListener()
- {
- }
-
-
- PhysicContactCallbackListener::PhysicContactCallbackListener()
- {
- }
-
- PhysicContactCallbackListener::~PhysicContactCallbackListener()
- {
- }
-
-
- PhysicContactListener* PhysicContactDispatcher::AddContactListener(PhysicContactListenerPtr listener)
- {
- return AddContactListener(listener.get());
- }
-
- PhysicContactListener* PhysicContactDispatcher::AddContactListener(PhysicContactListener* listener)
- {
- KGE_ASSERT(listener && "AddListener failed, NULL pointer exception");
-
- if (listener)
- {
- listeners_.push_back(listener);
- }
- return listener;
- }
-
- void PhysicContactDispatcher::StartContactListeners(String const& listener_name)
- {
- for (auto listener : listeners_)
- {
- if (listener->IsName(listener_name))
- {
- listener->Start();
- }
- }
- }
-
- void PhysicContactDispatcher::StopContactListeners(String const& listener_name)
- {
- for (auto listener : listeners_)
- {
- if (listener->IsName(listener_name))
- {
- listener->Stop();
- }
- }
- }
-
- void PhysicContactDispatcher::RemoveContactListeners(String const& listener_name)
- {
- PhysicContactListenerPtr next;
- for (auto listener = listeners_.first_item(); listener; listener = next)
- {
- next = listener->next_item();
-
- if (listener->IsName(listener_name))
- {
- listeners_.remove(listener);
- }
- }
- }
-
- void PhysicContactDispatcher::StartAllContactListeners()
- {
- for (auto listener : listeners_)
- {
- listener->Start();
- }
- }
-
- void PhysicContactDispatcher::StopAllContactListeners()
- {
- for (auto listener : listeners_)
- {
- listener->Stop();
- }
- }
-
- void PhysicContactDispatcher::RemoveAllContactListeners()
- {
- listeners_.clear();
- }
-
- void PhysicContactDispatcher::OnContactBegin(b2Contact* b2contact)
- {
- if (listeners_.empty())
- return;
-
- PhysicContact contact(b2contact);
- PhysicContactListenerPtr next;
- for (auto listener = listeners_.first_item(); listener; listener = next)
- {
- next = listener->next_item();
-
- if (listener->IsRunning())
- {
- listener->OnContactBegin(contact);
- }
- }
- }
-
- void PhysicContactDispatcher::OnContactEnd(b2Contact* b2contact)
- {
- if (listeners_.empty())
- return;
-
- PhysicContact contact(b2contact);
- PhysicContactListenerPtr next;
- for (auto listener = listeners_.first_item(); listener; listener = next)
- {
- next = listener->next_item();
-
- if (listener->IsRunning())
- {
- listener->OnContactEnd(contact);
- }
- }
- }
-
- }
-}
diff --git a/src/kiwano-physics/ContactListener.h b/src/kiwano-physics/ContactListener.h
deleted file mode 100644
index 9556d633..00000000
--- a/src/kiwano-physics/ContactListener.h
+++ /dev/null
@@ -1,141 +0,0 @@
-// Copyright (c) 2018-2019 Kiwano - Nomango
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-#pragma once
-#include
-
-namespace kiwano
-{
- namespace physics
- {
- class PhysicContactDispatcher;
-
- KGE_DECLARE_SMART_PTR(PhysicContactListener);
-
- // 接触监听器
- class KGE_API PhysicContactListener
- : public ObjectBase
- , protected IntrusiveListItem
- {
- friend IntrusiveList;
- friend class PhysicContactDispatcher;
-
- public:
- PhysicContactListener();
- virtual ~PhysicContactListener();
-
- // 接触开始
- virtual void OnContactBegin(PhysicContact contact) { KGE_NOT_USED(contact); }
-
- // 接触结束
- virtual void OnContactEnd(PhysicContact contact) { KGE_NOT_USED(contact); }
-
- inline void Start() { running_ = true; }
- inline void Stop() { running_ = true; }
- inline bool IsRunning() const { return running_; }
-
- protected:
- bool running_;
- };
-
-
- KGE_DECLARE_SMART_PTR(PhysicContactCallbackListener);
-
- // 接触回调监听器
- class KGE_API PhysicContactCallbackListener
- : public PhysicContactListener
- {
- friend IntrusiveList;
- friend class PhysicContactDispatcher;
-
- public:
- using ContactBeginCallback = Function;
- using ContactEndCallback = Function;
-
- PhysicContactCallbackListener();
- virtual ~PhysicContactCallbackListener();
-
- // 接触开始回调
- void SetCallbackOnContactBegin(ContactBeginCallback const& cb) { begin_ = cb; }
- ContactBeginCallback GetCallbackOnContactBegin() const { return begin_; }
-
- // 接触结束回调
- void SetCallbackOnContactEnd(ContactEndCallback const& cb) { end_ = cb; }
- ContactEndCallback GetCallbackOnContactEnd() const { return end_; }
-
- void OnContactBegin(PhysicContact contact) override { if (begin_) begin_(contact); }
- void OnContactEnd(PhysicContact contact) override { if (end_) end_(contact); }
-
- protected:
- ContactBeginCallback begin_;
- ContactEndCallback end_;
- };
-
-
- // 接触分发器
- class KGE_API PhysicContactDispatcher
- {
- public:
- using Listeners = IntrusiveList;
-
- // 添加监听器
- PhysicContactListener* AddContactListener(
- PhysicContactListenerPtr listener
- );
-
- // 添加监听器
- PhysicContactListener* AddContactListener(
- PhysicContactListener* listener
- );
-
- // 启动监听器
- void StartContactListeners(
- String const& listener_name
- );
-
- // 停止监听器
- void StopContactListeners(
- String const& listener_name
- );
-
- // 移除监听器
- void RemoveContactListeners(
- String const& listener_name
- );
-
- // 启动所有监听器
- void StartAllContactListeners();
-
- // 停止所有监听器
- void StopAllContactListeners();
-
- // 移除所有监听器
- void RemoveAllContactListeners();
-
- protected:
- void OnContactBegin(b2Contact* contact);
-
- void OnContactEnd(b2Contact* contact);
-
- private:
- Listeners listeners_;
- };
- }
-}
diff --git a/src/kiwano-physics/Fixture.cpp b/src/kiwano-physics/Fixture.cpp
index 35f264e6..dc6a8c52 100644
--- a/src/kiwano-physics/Fixture.cpp
+++ b/src/kiwano-physics/Fixture.cpp
@@ -27,19 +27,19 @@ namespace kiwano
namespace physics
{
- PhysicFixture::PhysicFixture()
+ Fixture::Fixture()
: fixture_(nullptr)
{
}
- PhysicFixture::PhysicFixture(b2Fixture* fixture)
- : PhysicFixture()
+ Fixture::Fixture(b2Fixture* fixture)
+ : Fixture()
{
SetB2Fixture(fixture);
}
- PhysicFixture::PhysicFixture(PhysicBody* body, PhysicShape* shape, const Param& param)
- : PhysicFixture()
+ Fixture::Fixture(Body* body, Shape* shape, const Param& param)
+ : Fixture()
{
KGE_ASSERT(body);
@@ -58,38 +58,38 @@ namespace kiwano
}
}
- PhysicBody* PhysicFixture::GetBody()
+ Body* Fixture::GetBody()
{
KGE_ASSERT(fixture_);
- return static_cast(fixture_->GetBody()->GetUserData());
+ return static_cast(fixture_->GetBody()->GetUserData());
}
- const PhysicBody* PhysicFixture::GetBody() const
+ const Body* Fixture::GetBody() const
{
KGE_ASSERT(fixture_);
- return static_cast(fixture_->GetBody()->GetUserData());
+ return static_cast(fixture_->GetBody()->GetUserData());
}
- PhysicShape PhysicFixture::GetShape() const
+ Shape Fixture::GetShape() const
{
KGE_ASSERT(fixture_);
- return PhysicShape(fixture_->GetShape());
+ return Shape(fixture_->GetShape());
}
- PhysicFixture PhysicFixture::GetNext() const
+ Fixture Fixture::GetNext() const
{
KGE_ASSERT(fixture_);
- return PhysicFixture(fixture_->GetNext());
+ return Fixture(fixture_->GetNext());
}
- void PhysicFixture::GetMassData(float* mass, Point* center, float* inertia) const
+ void Fixture::GetMassData(float* mass, Point* center, float* inertia) const
{
KGE_ASSERT(fixture_);
- const PhysicBody* body = GetBody();
+ const Body* body = GetBody();
KGE_ASSERT(body);
- const PhysicWorld* world = body->GetWorld();
+ const World* world = body->GetWorld();
KGE_ASSERT(world);
b2MassData data;
@@ -100,14 +100,14 @@ namespace kiwano
if (inertia) *inertia = data.I;
}
- bool PhysicFixture::TestPoint(const Point& p) const
+ bool Fixture::TestPoint(const Point& p) const
{
KGE_ASSERT(fixture_);
- const PhysicBody* body = GetBody();
+ const Body* body = GetBody();
KGE_ASSERT(body);
- const PhysicWorld* world = body->GetWorld();
+ const World* world = body->GetWorld();
KGE_ASSERT(world);
return fixture_->TestPoint(world->Stage2World(p));
diff --git a/src/kiwano-physics/Fixture.h b/src/kiwano-physics/Fixture.h
index 85cb3895..2097d5a2 100644
--- a/src/kiwano-physics/Fixture.h
+++ b/src/kiwano-physics/Fixture.h
@@ -26,10 +26,10 @@ namespace kiwano
{
namespace physics
{
- class PhysicBody;
+ class Body;
// 夹具
- class PhysicFixture
+ class Fixture
{
public:
struct Param
@@ -49,19 +49,19 @@ namespace kiwano
{}
};
- PhysicFixture();
- PhysicFixture(b2Fixture* fixture);
- PhysicFixture(PhysicBody* body, PhysicShape* shape, const Param& param);
+ Fixture();
+ Fixture(b2Fixture* fixture);
+ Fixture(Body* body, Shape* shape, const Param& param);
// 物体
- PhysicBody* GetBody();
- const PhysicBody* GetBody() const;
+ Body* GetBody();
+ const Body* GetBody() const;
// 形状
- PhysicShape GetShape() const;
+ Shape GetShape() const;
// 下一夹具 (同一物体上)
- PhysicFixture GetNext() const;
+ Fixture GetNext() const;
// 接触传感器
bool IsSensor() const { KGE_ASSERT(fixture_); return fixture_->IsSensor(); }
diff --git a/src/kiwano-physics/Joint.cpp b/src/kiwano-physics/Joint.cpp
index e32a2598..08be38b7 100644
--- a/src/kiwano-physics/Joint.cpp
+++ b/src/kiwano-physics/Joint.cpp
@@ -26,29 +26,29 @@ namespace kiwano
namespace physics
{
//
- // PhysicJoint
+ // Joint
//
- PhysicJoint::PhysicJoint()
+ Joint::Joint()
: joint_(nullptr)
, world_(nullptr)
, type_(Type::Unknown)
{
}
- PhysicJoint::PhysicJoint(b2Joint* joint)
- : PhysicJoint()
+ Joint::Joint(b2Joint* joint)
+ : Joint()
{
SetB2Joint(joint);
}
- PhysicJoint::PhysicJoint(PhysicWorld* world, b2JointDef* joint_def)
- : PhysicJoint()
+ Joint::Joint(World* world, b2JointDef* joint_def)
+ : Joint()
{
Init(world, joint_def);
}
- PhysicJoint::~PhysicJoint()
+ Joint::~Joint()
{
if (world_)
{
@@ -56,7 +56,7 @@ namespace kiwano
}
}
- void PhysicJoint::Init(PhysicWorld* world, b2JointDef* joint_def)
+ void Joint::Init(World* world, b2JointDef* joint_def)
{
world_ = world;
if (world_)
@@ -68,28 +68,28 @@ namespace kiwano
}
}
- PhysicBodyPtr PhysicJoint::GetBodyA() const
+ BodyPtr Joint::GetBodyA() const
{
KGE_ASSERT(joint_);
b2Body* body = joint_->GetBodyA();
- return PhysicBodyPtr(static_cast(body->GetUserData()));
+ return BodyPtr(static_cast(body->GetUserData()));
}
- PhysicBodyPtr PhysicJoint::GetBodyB() const
+ BodyPtr Joint::GetBodyB() const
{
KGE_ASSERT(joint_);
b2Body* body = joint_->GetBodyB();
- return PhysicBodyPtr(static_cast(body->GetUserData()));
+ return BodyPtr(static_cast(body->GetUserData()));
}
- void PhysicJoint::SetB2Joint(b2Joint* joint)
+ void Joint::SetB2Joint(b2Joint* joint)
{
joint_ = joint;
if (joint_)
{
- type_ = PhysicJoint::Type(joint_->GetType());
+ type_ = Joint::Type(joint_->GetType());
}
}
@@ -98,19 +98,19 @@ namespace kiwano
//
DistanceJoint::DistanceJoint()
- : PhysicJoint()
+ : Joint()
, raw_joint_(nullptr)
{
}
- DistanceJoint::DistanceJoint(PhysicWorld* world, b2DistanceJointDef* def)
- : PhysicJoint(world, def)
+ DistanceJoint::DistanceJoint(World* world, b2DistanceJointDef* def)
+ : Joint(world, def)
, raw_joint_(nullptr)
{
}
- DistanceJoint::DistanceJoint(PhysicWorld* world, DistanceJoint::Param const& param)
- : PhysicJoint()
+ DistanceJoint::DistanceJoint(World* world, DistanceJoint::Param const& param)
+ : Joint()
, raw_joint_(nullptr)
{
KGE_ASSERT(param.body_a && param.body_b);
@@ -141,19 +141,19 @@ namespace kiwano
//
FrictionJoint::FrictionJoint()
- : PhysicJoint()
+ : Joint()
, raw_joint_(nullptr)
{
}
- FrictionJoint::FrictionJoint(PhysicWorld* world, b2FrictionJointDef* def)
- : PhysicJoint(world, def)
+ FrictionJoint::FrictionJoint(World* world, b2FrictionJointDef* def)
+ : Joint(world, def)
, raw_joint_(nullptr)
{
}
- FrictionJoint::FrictionJoint(PhysicWorld* world, FrictionJoint::Param const& param)
- : PhysicJoint()
+ FrictionJoint::FrictionJoint(World* world, FrictionJoint::Param const& param)
+ : Joint()
, raw_joint_(nullptr)
{
KGE_ASSERT(param.body_a && param.body_b);
@@ -196,19 +196,19 @@ namespace kiwano
//
GearJoint::GearJoint()
- : PhysicJoint()
+ : Joint()
, raw_joint_(nullptr)
{
}
- GearJoint::GearJoint(PhysicWorld* world, b2GearJointDef* def)
- : PhysicJoint(world, def)
+ GearJoint::GearJoint(World* world, b2GearJointDef* def)
+ : Joint(world, def)
, raw_joint_(nullptr)
{
}
- GearJoint::GearJoint(PhysicWorld* world, GearJoint::Param const& param)
- : PhysicJoint()
+ GearJoint::GearJoint(World* world, GearJoint::Param const& param)
+ : Joint()
, raw_joint_(nullptr)
{
KGE_ASSERT(param.joint_a && param.joint_b);
@@ -239,19 +239,19 @@ namespace kiwano
//
MotorJoint::MotorJoint()
- : PhysicJoint()
+ : Joint()
, raw_joint_(nullptr)
{
}
- MotorJoint::MotorJoint(PhysicWorld* world, b2MotorJointDef* def)
- : PhysicJoint(world, def)
+ MotorJoint::MotorJoint(World* world, b2MotorJointDef* def)
+ : Joint(world, def)
, raw_joint_(nullptr)
{
}
- MotorJoint::MotorJoint(PhysicWorld* world, MotorJoint::Param const& param)
- : PhysicJoint()
+ MotorJoint::MotorJoint(World* world, MotorJoint::Param const& param)
+ : Joint()
, raw_joint_(nullptr)
{
KGE_ASSERT(param.body_a && param.body_b);
@@ -294,19 +294,19 @@ namespace kiwano
//
PrismaticJoint::PrismaticJoint()
- : PhysicJoint()
+ : Joint()
, raw_joint_(nullptr)
{
}
- PrismaticJoint::PrismaticJoint(PhysicWorld* world, b2PrismaticJointDef* def)
- : PhysicJoint(world, def)
+ PrismaticJoint::PrismaticJoint(World* world, b2PrismaticJointDef* def)
+ : Joint(world, def)
, raw_joint_(nullptr)
{
}
- PrismaticJoint::PrismaticJoint(PhysicWorld* world, PrismaticJoint::Param const& param)
- : PhysicJoint()
+ PrismaticJoint::PrismaticJoint(World* world, PrismaticJoint::Param const& param)
+ : Joint()
, raw_joint_(nullptr)
{
KGE_ASSERT(param.body_a && param.body_b);
@@ -359,19 +359,19 @@ namespace kiwano
//
PulleyJoint::PulleyJoint()
- : PhysicJoint()
+ : Joint()
, raw_joint_(nullptr)
{
}
- PulleyJoint::PulleyJoint(PhysicWorld* world, b2PulleyJointDef* def)
- : PhysicJoint(world, def)
+ PulleyJoint::PulleyJoint(World* world, b2PulleyJointDef* def)
+ : Joint(world, def)
, raw_joint_(nullptr)
{
}
- PulleyJoint::PulleyJoint(PhysicWorld* world, PulleyJoint::Param const& param)
- : PhysicJoint()
+ PulleyJoint::PulleyJoint(World* world, PulleyJoint::Param const& param)
+ : Joint()
, raw_joint_(nullptr)
{
KGE_ASSERT(param.body_a && param.body_b);
@@ -431,19 +431,19 @@ namespace kiwano
//
RevoluteJoint::RevoluteJoint()
- : PhysicJoint()
+ : Joint()
, raw_joint_(nullptr)
{
}
- RevoluteJoint::RevoluteJoint(PhysicWorld* world, b2RevoluteJointDef* def)
- : PhysicJoint(world, def)
+ RevoluteJoint::RevoluteJoint(World* world, b2RevoluteJointDef* def)
+ : Joint(world, def)
, raw_joint_(nullptr)
{
}
- RevoluteJoint::RevoluteJoint(PhysicWorld* world, RevoluteJoint::Param const& param)
- : PhysicJoint()
+ RevoluteJoint::RevoluteJoint(World* world, RevoluteJoint::Param const& param)
+ : Joint()
, raw_joint_(nullptr)
{
KGE_ASSERT(param.body_a && param.body_b);
@@ -508,19 +508,19 @@ namespace kiwano
//
RopeJoint::RopeJoint()
- : PhysicJoint()
+ : Joint()
, raw_joint_(nullptr)
{
}
- RopeJoint::RopeJoint(PhysicWorld* world, b2RopeJointDef* def)
- : PhysicJoint(world, def)
+ RopeJoint::RopeJoint(World* world, b2RopeJointDef* def)
+ : Joint(world, def)
, raw_joint_(nullptr)
{
}
- RopeJoint::RopeJoint(PhysicWorld* world, RopeJoint::Param const& param)
- : PhysicJoint()
+ RopeJoint::RopeJoint(World* world, RopeJoint::Param const& param)
+ : Joint()
, raw_joint_(nullptr)
{
KGE_ASSERT(param.body_a && param.body_b);
@@ -553,19 +553,19 @@ namespace kiwano
//
WeldJoint::WeldJoint()
- : PhysicJoint()
+ : Joint()
, raw_joint_(nullptr)
{
}
- WeldJoint::WeldJoint(PhysicWorld* world, b2WeldJointDef* def)
- : PhysicJoint(world, def)
+ WeldJoint::WeldJoint(World* world, b2WeldJointDef* def)
+ : Joint(world, def)
, raw_joint_(nullptr)
{
}
- WeldJoint::WeldJoint(PhysicWorld* world, WeldJoint::Param const& param)
- : PhysicJoint()
+ WeldJoint::WeldJoint(World* world, WeldJoint::Param const& param)
+ : Joint()
, raw_joint_(nullptr)
{
KGE_ASSERT(param.body_a && param.body_b);
@@ -584,19 +584,19 @@ namespace kiwano
//
WheelJoint::WheelJoint()
- : PhysicJoint()
+ : Joint()
, raw_joint_(nullptr)
{
}
- WheelJoint::WheelJoint(PhysicWorld* world, b2WheelJointDef* def)
- : PhysicJoint(world, def)
+ WheelJoint::WheelJoint(World* world, b2WheelJointDef* def)
+ : Joint(world, def)
, raw_joint_(nullptr)
{
}
- WheelJoint::WheelJoint(PhysicWorld* world, WheelJoint::Param const& param)
- : PhysicJoint()
+ WheelJoint::WheelJoint(World* world, WheelJoint::Param const& param)
+ : Joint()
, raw_joint_(nullptr)
{
KGE_ASSERT(param.body_a && param.body_b);
@@ -642,19 +642,19 @@ namespace kiwano
//
MouseJoint::MouseJoint()
- : PhysicJoint()
+ : Joint()
, raw_joint_(nullptr)
{
}
- MouseJoint::MouseJoint(PhysicWorld* world, b2MouseJointDef* def)
- : PhysicJoint(world, def)
+ MouseJoint::MouseJoint(World* world, b2MouseJointDef* def)
+ : Joint(world, def)
, raw_joint_(nullptr)
{
}
- MouseJoint::MouseJoint(PhysicWorld* world, MouseJoint::Param const& param)
- : PhysicJoint()
+ MouseJoint::MouseJoint(World* world, MouseJoint::Param const& param)
+ : Joint()
, raw_joint_(nullptr)
{
KGE_ASSERT(param.body_a && param.body_b);
diff --git a/src/kiwano-physics/Joint.h b/src/kiwano-physics/Joint.h
index e2a8b0df..46548a4f 100644
--- a/src/kiwano-physics/Joint.h
+++ b/src/kiwano-physics/Joint.h
@@ -26,7 +26,7 @@ namespace kiwano
{
namespace physics
{
- KGE_DECLARE_SMART_PTR(PhysicJoint);
+ KGE_DECLARE_SMART_PTR(Joint);
KGE_DECLARE_SMART_PTR(DistanceJoint);
KGE_DECLARE_SMART_PTR(FrictionJoint);
KGE_DECLARE_SMART_PTR(GearJoint);
@@ -40,7 +40,7 @@ namespace kiwano
KGE_DECLARE_SMART_PTR(WheelJoint);
// 关节
- class KGE_API PhysicJoint
+ class KGE_API Joint
: public virtual RefCounter
{
public:
@@ -62,43 +62,43 @@ namespace kiwano
struct ParamBase
{
- PhysicBody* body_a;
- PhysicBody* body_b;
+ Body* body_a;
+ Body* body_b;
- ParamBase(PhysicBody* body_a, PhysicBody* body_b) : body_a(body_a), body_b(body_b) {}
- ParamBase(PhysicBodyPtr body_a, PhysicBodyPtr body_b) : body_a(body_a.get()), body_b(body_b.get()) {}
+ ParamBase(Body* body_a, Body* body_b) : body_a(body_a), body_b(body_b) {}
+ ParamBase(BodyPtr body_a, BodyPtr body_b) : body_a(body_a.get()), body_b(body_b.get()) {}
};
- PhysicJoint();
- PhysicJoint(b2Joint* joint);
- PhysicJoint(PhysicWorld* world, b2JointDef* joint_def);
- virtual ~PhysicJoint();
+ Joint();
+ Joint(b2Joint* joint);
+ Joint(World* world, b2JointDef* joint_def);
+ virtual ~Joint();
- void Init(PhysicWorld* world, b2JointDef* joint_def);
+ void Init(World* world, b2JointDef* joint_def);
- PhysicBodyPtr GetBodyA() const;
- PhysicBodyPtr GetBodyB() const;
+ BodyPtr GetBodyA() const;
+ BodyPtr GetBodyB() const;
b2Joint* GetB2Joint() { return joint_; }
const b2Joint* GetB2Joint() const { return joint_; }
void SetB2Joint(b2Joint* joint);
- PhysicWorld* GetWorld() { return world_; }
- const PhysicWorld* GetWorld() const { return world_; }
+ World* GetWorld() { return world_; }
+ const World* GetWorld() const { return world_; }
protected:
b2Joint* joint_;
- PhysicWorld* world_;
+ World* world_;
Type type_;
};
// 固定距离关节
class KGE_API DistanceJoint
- : public PhysicJoint
+ : public Joint
{
public:
- struct Param : public PhysicJoint::ParamBase
+ struct Param : public Joint::ParamBase
{
Point anchor_a;
Point anchor_b;
@@ -106,8 +106,8 @@ namespace kiwano
float damping_ratio;
Param(
- PhysicBody* body_a,
- PhysicBody* body_b,
+ Body* body_a,
+ Body* body_b,
Point const& anchor_a,
Point const& anchor_b,
float frequency_hz = 0.f,
@@ -121,8 +121,8 @@ namespace kiwano
{}
Param(
- PhysicBodyPtr body_a,
- PhysicBodyPtr body_b,
+ BodyPtr body_a,
+ BodyPtr body_b,
Point const& anchor_a,
Point const& anchor_b,
float frequency_hz = 0.f,
@@ -133,8 +133,8 @@ namespace kiwano
};
DistanceJoint();
- DistanceJoint(PhysicWorld* world, b2DistanceJointDef* def);
- DistanceJoint(PhysicWorld* world, Param const& param);
+ DistanceJoint(World* world, b2DistanceJointDef* def);
+ DistanceJoint(World* world, Param const& param);
void SetLength(float length);
float GetLength() const;
@@ -154,18 +154,18 @@ namespace kiwano
// 摩擦关节
class KGE_API FrictionJoint
- : public PhysicJoint
+ : public Joint
{
public:
- struct Param : public PhysicJoint::ParamBase
+ struct Param : public Joint::ParamBase
{
Point anchor;
float max_force;
float max_torque;
Param(
- PhysicBody* body_a,
- PhysicBody* body_b,
+ Body* body_a,
+ Body* body_b,
Point const& anchor,
float max_force = 0.f,
float max_torque = 0.f
@@ -177,8 +177,8 @@ namespace kiwano
{}
Param(
- PhysicBodyPtr body_a,
- PhysicBodyPtr body_b,
+ BodyPtr body_a,
+ BodyPtr body_b,
Point const& anchor,
float max_force = 0.f,
float max_torque = 0.f
@@ -188,8 +188,8 @@ namespace kiwano
};
FrictionJoint();
- FrictionJoint(PhysicWorld* world, b2FrictionJointDef* def);
- FrictionJoint(PhysicWorld* world, Param const& param);
+ FrictionJoint(World* world, b2FrictionJointDef* def);
+ FrictionJoint(World* world, Param const& param);
// 设定最大摩擦力
void SetMaxForce(float force);
@@ -206,18 +206,18 @@ namespace kiwano
// 齿轮关节
class KGE_API GearJoint
- : public PhysicJoint
+ : public Joint
{
public:
- struct Param : public PhysicJoint::ParamBase
+ struct Param : public Joint::ParamBase
{
- PhysicJointPtr joint_a;
- PhysicJointPtr joint_b;
+ JointPtr joint_a;
+ JointPtr joint_b;
float ratio;
Param(
- PhysicJoint* joint_a,
- PhysicJoint* joint_b,
+ Joint* joint_a,
+ Joint* joint_b,
float ratio = 1.f
)
: ParamBase(nullptr, nullptr)
@@ -227,8 +227,8 @@ namespace kiwano
{}
Param(
- PhysicJointPtr joint_a,
- PhysicJointPtr joint_b,
+ JointPtr joint_a,
+ JointPtr joint_b,
float ratio = 1.f
)
: Param(joint_a.get(), joint_b.get(), ratio)
@@ -236,8 +236,8 @@ namespace kiwano
};
GearJoint();
- GearJoint(PhysicWorld* world, b2GearJointDef* def);
- GearJoint(PhysicWorld* world, Param const& param);
+ GearJoint(World* world, b2GearJointDef* def);
+ GearJoint(World* world, Param const& param);
// 设定齿轮传动比
void SetRatio(float ratio);
@@ -250,18 +250,18 @@ namespace kiwano
// 马达关节
class KGE_API MotorJoint
- : public PhysicJoint
+ : public Joint
{
public:
- struct Param : public PhysicJoint::ParamBase
+ struct Param : public Joint::ParamBase
{
float max_force;
float max_torque;
float correction_factor;
Param(
- PhysicBody* body_a,
- PhysicBody* body_b,
+ Body* body_a,
+ Body* body_b,
float max_force = 1.f,
float max_torque = 100.f,
float correction_factor = 0.3f
@@ -273,8 +273,8 @@ namespace kiwano
{}
Param(
- PhysicBodyPtr body_a,
- PhysicBodyPtr body_b,
+ BodyPtr body_a,
+ BodyPtr body_b,
float max_force = 0.f,
float max_torque = 0.f,
float correction_factor = 0.3f
@@ -284,8 +284,8 @@ namespace kiwano
};
MotorJoint();
- MotorJoint(PhysicWorld* world, b2MotorJointDef* def);
- MotorJoint(PhysicWorld* world, Param const& param);
+ MotorJoint(World* world, b2MotorJointDef* def);
+ MotorJoint(World* world, Param const& param);
// 设定最大摩擦力
void SetMaxForce(float force);
@@ -302,10 +302,10 @@ namespace kiwano
// 平移关节
class KGE_API PrismaticJoint
- : public PhysicJoint
+ : public Joint
{
public:
- struct Param : public PhysicJoint::ParamBase
+ struct Param : public Joint::ParamBase
{
Point anchor;
Vec2 axis;
@@ -317,8 +317,8 @@ namespace kiwano
float motor_speed;
Param(
- PhysicBody* body_a,
- PhysicBody* body_b,
+ Body* body_a,
+ Body* body_b,
Point const& anchor,
Vec2 const& axis,
bool enable_limit = false,
@@ -340,8 +340,8 @@ namespace kiwano
{}
Param(
- PhysicBodyPtr body_a,
- PhysicBodyPtr body_b,
+ BodyPtr body_a,
+ BodyPtr body_b,
Point const& anchor,
Vec2 const& axis,
bool enable_limit = false,
@@ -356,8 +356,8 @@ namespace kiwano
};
PrismaticJoint();
- PrismaticJoint(PhysicWorld* world, b2PrismaticJointDef* def);
- PrismaticJoint(PhysicWorld* world, Param const& param);
+ PrismaticJoint(World* world, b2PrismaticJointDef* def);
+ PrismaticJoint(World* world, Param const& param);
float GetReferenceAngle() const { KGE_ASSERT(raw_joint_); return math::Radian2Degree(raw_joint_->GetReferenceAngle()); }
float GetJointTranslation() const;
@@ -388,10 +388,10 @@ namespace kiwano
// 滑轮关节
class KGE_API PulleyJoint
- : public PhysicJoint
+ : public Joint
{
public:
- struct Param : public PhysicJoint::ParamBase
+ struct Param : public Joint::ParamBase
{
Point anchor_a;
Point anchor_b;
@@ -400,8 +400,8 @@ namespace kiwano
float ratio;
Param(
- PhysicBody* body_a,
- PhysicBody* body_b,
+ Body* body_a,
+ Body* body_b,
Point const& anchor_a,
Point const& anchor_b,
Point const& ground_anchor_a,
@@ -417,8 +417,8 @@ namespace kiwano
{}
Param(
- PhysicBodyPtr body_a,
- PhysicBodyPtr body_b,
+ BodyPtr body_a,
+ BodyPtr body_b,
Point const& anchor_a,
Point const& anchor_b,
Point const& ground_anchor_a,
@@ -430,8 +430,8 @@ namespace kiwano
};
PulleyJoint();
- PulleyJoint(PhysicWorld* world, b2PulleyJointDef* def);
- PulleyJoint(PhysicWorld* world, Param const& param);
+ PulleyJoint(World* world, b2PulleyJointDef* def);
+ PulleyJoint(World* world, Param const& param);
Point GetGroundAnchorA() const;
Point GetGroundAnchorB() const;
@@ -451,10 +451,10 @@ namespace kiwano
// 旋转关节
class KGE_API RevoluteJoint
- : public PhysicJoint
+ : public Joint
{
public:
- struct Param : public PhysicJoint::ParamBase
+ struct Param : public Joint::ParamBase
{
Point anchor;
bool enable_limit;
@@ -465,8 +465,8 @@ namespace kiwano
float motor_speed;
Param(
- PhysicBody* body_a,
- PhysicBody* body_b,
+ Body* body_a,
+ Body* body_b,
Point const& anchor,
bool enable_limit = false,
float lower_angle = 0.0f,
@@ -486,8 +486,8 @@ namespace kiwano
{}
Param(
- PhysicBodyPtr body_a,
- PhysicBodyPtr body_b,
+ BodyPtr body_a,
+ BodyPtr body_b,
Point const& anchor,
bool enable_limit = false,
float lower_angle = 0.0f,
@@ -501,8 +501,8 @@ namespace kiwano
};
RevoluteJoint();
- RevoluteJoint(PhysicWorld* world, b2RevoluteJointDef* def);
- RevoluteJoint(PhysicWorld* world, Param const& param);
+ RevoluteJoint(World* world, b2RevoluteJointDef* def);
+ RevoluteJoint(World* world, Param const& param);
float GetReferenceAngle() const { KGE_ASSERT(raw_joint_); return math::Radian2Degree(raw_joint_->GetReferenceAngle()); }
float GetJointAngle() const;
@@ -533,18 +533,18 @@ namespace kiwano
// 绳关节
class KGE_API RopeJoint
- : public PhysicJoint
+ : public Joint
{
public:
- struct Param : public PhysicJoint::ParamBase
+ struct Param : public Joint::ParamBase
{
Point local_anchor_a;
Point local_anchor_b;
float max_length;
Param(
- PhysicBody* body_a,
- PhysicBody* body_b,
+ Body* body_a,
+ Body* body_b,
Point const& local_anchor_a,
Point const& local_anchor_b,
float max_length = 0.f
@@ -556,8 +556,8 @@ namespace kiwano
{}
Param(
- PhysicBodyPtr body_a,
- PhysicBodyPtr body_b,
+ BodyPtr body_a,
+ BodyPtr body_b,
Point const& local_anchor_a,
Point const& local_anchor_b,
float max_length = 0.f
@@ -567,8 +567,8 @@ namespace kiwano
};
RopeJoint();
- RopeJoint(PhysicWorld* world, b2RopeJointDef* def);
- RopeJoint(PhysicWorld* world, Param const& param);
+ RopeJoint(World* world, b2RopeJointDef* def);
+ RopeJoint(World* world, Param const& param);
void SetMaxLength(float length);
float GetMaxLength() const;
@@ -580,18 +580,18 @@ namespace kiwano
// 焊接关节
class KGE_API WeldJoint
- : public PhysicJoint
+ : public Joint
{
public:
- struct Param : public PhysicJoint::ParamBase
+ struct Param : public Joint::ParamBase
{
Point anchor;
float frequency_hz;
float damping_ratio;
Param(
- PhysicBody* body_a,
- PhysicBody* body_b,
+ Body* body_a,
+ Body* body_b,
Point const& anchor,
float frequency_hz = 0.f,
float damping_ratio = 0.f
@@ -603,8 +603,8 @@ namespace kiwano
{}
Param(
- PhysicBodyPtr body_a,
- PhysicBodyPtr body_b,
+ BodyPtr body_a,
+ BodyPtr body_b,
Point const& anchor,
float frequency_hz = 0.f,
float damping_ratio = 0.f
@@ -614,8 +614,8 @@ namespace kiwano
};
WeldJoint();
- WeldJoint(PhysicWorld* world, b2WeldJointDef* def);
- WeldJoint(PhysicWorld* world, Param const& param);
+ WeldJoint(World* world, b2WeldJointDef* def);
+ WeldJoint(World* world, Param const& param);
// 设置弹簧阻尼器频率 [赫兹]
void SetFrequency(float hz) { KGE_ASSERT(raw_joint_); raw_joint_->SetFrequency(hz); }
@@ -632,10 +632,10 @@ namespace kiwano
// 轮关节
class KGE_API WheelJoint
- : public PhysicJoint
+ : public Joint
{
public:
- struct Param : public PhysicJoint::ParamBase
+ struct Param : public Joint::ParamBase
{
Point anchor;
Vec2 axis;
@@ -646,8 +646,8 @@ namespace kiwano
float damping_ratio;
Param(
- PhysicBody* body_a,
- PhysicBody* body_b,
+ Body* body_a,
+ Body* body_b,
Point const& anchor,
Vec2 const& axis,
float frequency_hz = 2.0f,
@@ -667,8 +667,8 @@ namespace kiwano
{}
Param(
- PhysicBodyPtr body_a,
- PhysicBodyPtr body_b,
+ BodyPtr body_a,
+ BodyPtr body_b,
Point const& anchor,
Vec2 const& axis,
float frequency_hz = 2.0f,
@@ -682,8 +682,8 @@ namespace kiwano
};
WheelJoint();
- WheelJoint(PhysicWorld* world, b2WheelJointDef* def);
- WheelJoint(PhysicWorld* world, Param const& param);
+ WheelJoint(World* world, b2WheelJointDef* def);
+ WheelJoint(World* world, Param const& param);
float GetJointTranslation() const;
float GetJointLinearSpeed() const;
@@ -715,10 +715,10 @@ namespace kiwano
// 鼠标关节
// 用于使身体的某个点追踪世界上的指定点,例如让物体追踪鼠标位置
class KGE_API MouseJoint
- : public PhysicJoint
+ : public Joint
{
public:
- struct Param : public PhysicJoint::ParamBase
+ struct Param : public Joint::ParamBase
{
Point target;
float max_force;
@@ -726,8 +726,8 @@ namespace kiwano
float damping_ratio;
Param(
- PhysicBody* body_a,
- PhysicBody* body_b,
+ Body* body_a,
+ Body* body_b,
Point const& target,
float max_force,
float frequency_hz = 5.0f,
@@ -741,8 +741,8 @@ namespace kiwano
{}
Param(
- PhysicBodyPtr body_a,
- PhysicBodyPtr body_b,
+ BodyPtr body_a,
+ BodyPtr body_b,
Point const& target,
float max_force,
float frequency_hz = 5.0f,
@@ -753,8 +753,8 @@ namespace kiwano
};
MouseJoint();
- MouseJoint(PhysicWorld* world, b2MouseJointDef* def);
- MouseJoint(PhysicWorld* world, Param const& param);
+ MouseJoint(World* world, b2MouseJointDef* def);
+ MouseJoint(World* world, Param const& param);
// 设定最大摩擦力 [N]
void SetMaxForce(float force);
diff --git a/src/kiwano-physics/Shape.cpp b/src/kiwano-physics/Shape.cpp
index e380fa3b..47d6dc0d 100644
--- a/src/kiwano-physics/Shape.cpp
+++ b/src/kiwano-physics/Shape.cpp
@@ -25,55 +25,55 @@ namespace kiwano
{
namespace physics
{
- PhysicShape::PhysicShape()
+ Shape::Shape()
: shape_(nullptr)
{
}
- PhysicShape::PhysicShape(b2Shape* shape)
+ Shape::Shape(b2Shape* shape)
: shape_(shape)
{
}
- b2Shape* PhysicShape::GetB2Shape()
+ b2Shape* Shape::GetB2Shape()
{
return shape_;
}
- const b2Shape* PhysicShape::GetB2Shape() const
+ const b2Shape* Shape::GetB2Shape() const
{
return shape_;
}
- void PhysicShape::SetB2Shape(b2Shape* shape)
+ void Shape::SetB2Shape(b2Shape* shape)
{
shape_ = shape;
}
//
- // PhysicCircleShape
+ // CircleShape
//
- PhysicCircleShape::PhysicCircleShape()
- : PhysicShape(&circle_)
+ CircleShape::CircleShape()
+ : Shape(&circle_)
, circle_()
, radius_(0.f)
{
}
- PhysicCircleShape::PhysicCircleShape(float radius, Point const& offset)
- : PhysicCircleShape()
+ CircleShape::CircleShape(float radius, Point const& offset)
+ : CircleShape()
{
Set(radius, offset);
}
- void PhysicCircleShape::Set(float radius, Point const& offset)
+ void CircleShape::Set(float radius, Point const& offset)
{
radius_ = radius;
offset_ = offset;
}
- void PhysicCircleShape::FitWorld(PhysicWorld* world)
+ void CircleShape::FitWorld(World* world)
{
KGE_ASSERT(world);
circle_.m_radius = world->Stage2World(radius_);
@@ -81,30 +81,30 @@ namespace kiwano
}
//
- // PhysicBoxShape
+ // BoxShape
//
- PhysicBoxShape::PhysicBoxShape()
- : PhysicShape(&polygon_)
+ BoxShape::BoxShape()
+ : Shape(&polygon_)
, polygon_()
, rotation_(0.f)
{
}
- PhysicBoxShape::PhysicBoxShape(Vec2 const& size, Point const& offset, float rotation)
- : PhysicBoxShape()
+ BoxShape::BoxShape(Vec2 const& size, Point const& offset, float rotation)
+ : BoxShape()
{
Set(size, offset, rotation);
}
- void PhysicBoxShape::Set(Vec2 const& size, Point const& offset, float rotation)
+ void BoxShape::Set(Vec2 const& size, Point const& offset, float rotation)
{
box_size_ = size;
offset_ = offset;
rotation_ = rotation;
}
- void PhysicBoxShape::FitWorld(PhysicWorld* world)
+ void BoxShape::FitWorld(World* world)
{
KGE_ASSERT(world);
@@ -114,27 +114,27 @@ namespace kiwano
}
//
- // PhysicPolygonShape
+ // PolygonShape
//
- PhysicPolygonShape::PhysicPolygonShape()
- : PhysicShape(&polygon_)
+ PolygonShape::PolygonShape()
+ : Shape(&polygon_)
, polygon_()
{
}
- PhysicPolygonShape::PhysicPolygonShape(Vector const& vertexs)
- : PhysicPolygonShape()
+ PolygonShape::PolygonShape(Vector const& vertexs)
+ : PolygonShape()
{
Set(vertexs);
}
- void PhysicPolygonShape::Set(Vector const& vertexs)
+ void PolygonShape::Set(Vector const& vertexs)
{
vertexs_ = vertexs;
}
- void PhysicPolygonShape::FitWorld(PhysicWorld* world)
+ void PolygonShape::FitWorld(World* world)
{
KGE_ASSERT(world);
@@ -149,28 +149,28 @@ namespace kiwano
}
//
- // PhysicEdgeShape
+ // EdgeShape
//
- PhysicEdgeShape::PhysicEdgeShape()
- : PhysicShape(&edge_)
+ EdgeShape::EdgeShape()
+ : Shape(&edge_)
, edge_()
{
}
- PhysicEdgeShape::PhysicEdgeShape(Point const& p1, Point const& p2)
- : PhysicEdgeShape()
+ EdgeShape::EdgeShape(Point const& p1, Point const& p2)
+ : EdgeShape()
{
Set(p1, p2);
}
- void PhysicEdgeShape::Set(Point const& p1, Point const& p2)
+ void EdgeShape::Set(Point const& p1, Point const& p2)
{
p_[0] = p1;
p_[1] = p2;
}
- void PhysicEdgeShape::FitWorld(PhysicWorld* world)
+ void EdgeShape::FitWorld(World* world)
{
KGE_ASSERT(world);
@@ -180,29 +180,29 @@ namespace kiwano
}
//
- // PhysicChainShape
+ // ChainShape
//
- PhysicChainShape::PhysicChainShape()
- : PhysicShape(&chain_)
+ ChainShape::ChainShape()
+ : Shape(&chain_)
, chain_()
, loop_(false)
{
}
- PhysicChainShape::PhysicChainShape(Vector const& vertexs, bool loop)
- : PhysicChainShape()
+ ChainShape::ChainShape(Vector const& vertexs, bool loop)
+ : ChainShape()
{
Set(vertexs, loop);
}
- void PhysicChainShape::Set(Vector const& vertexs, bool loop)
+ void ChainShape::Set(Vector const& vertexs, bool loop)
{
vertexs_ = vertexs;
loop_ = loop;
}
- void PhysicChainShape::FitWorld(PhysicWorld* world)
+ void ChainShape::FitWorld(World* world)
{
KGE_ASSERT(world);
diff --git a/src/kiwano-physics/Shape.h b/src/kiwano-physics/Shape.h
index 1d51a5df..0d891f62 100644
--- a/src/kiwano-physics/Shape.h
+++ b/src/kiwano-physics/Shape.h
@@ -25,37 +25,37 @@ namespace kiwano
{
namespace physics
{
- class PhysicWorld;
+ class World;
// 形状基类
- class KGE_API PhysicShape
+ class KGE_API Shape
{
public:
- PhysicShape();
- PhysicShape(b2Shape* shape);
+ Shape();
+ Shape(b2Shape* shape);
b2Shape* GetB2Shape();
const b2Shape* GetB2Shape() const;
void SetB2Shape(b2Shape* shape);
- virtual void FitWorld(PhysicWorld* world) {}
+ virtual void FitWorld(World* world) {}
protected:
b2Shape* shape_;
};
// 圆形形状
- class KGE_API PhysicCircleShape
- : public PhysicShape
+ class KGE_API CircleShape
+ : public Shape
{
public:
- PhysicCircleShape();
+ CircleShape();
- PhysicCircleShape(float radius, Point const& offset = Point());
+ CircleShape(float radius, Point const& offset = Point());
void Set(float radius, Point const& offset = Point());
- void FitWorld(PhysicWorld* world) override;
+ void FitWorld(World* world) override;
protected:
float radius_;
@@ -64,17 +64,17 @@ namespace kiwano
};
// 盒子形状
- class KGE_API PhysicBoxShape
- : public PhysicShape
+ class KGE_API BoxShape
+ : public Shape
{
public:
- PhysicBoxShape();
+ BoxShape();
- PhysicBoxShape(Vec2 const& size, Point const& offset = Point(), float rotation = 0.f);
+ BoxShape(Vec2 const& size, Point const& offset = Point(), float rotation = 0.f);
void Set(Vec2 const& size, Point const& offset = Point(), float rotation = 0.f);
- void FitWorld(PhysicWorld* world) override;
+ void FitWorld(World* world) override;
protected:
float rotation_;
@@ -84,17 +84,17 @@ namespace kiwano
};
// 多边形形状
- class KGE_API PhysicPolygonShape
- : public PhysicShape
+ class KGE_API PolygonShape
+ : public Shape
{
public:
- PhysicPolygonShape();
+ PolygonShape();
- PhysicPolygonShape(Vector const& vertexs);
+ PolygonShape(Vector const& vertexs);
void Set(Vector const& vertexs);
- void FitWorld(PhysicWorld* world) override;
+ void FitWorld(World* world) override;
protected:
Vector vertexs_;
@@ -102,17 +102,17 @@ namespace kiwano
};
// 线段形状, 用于表示一条边
- class KGE_API PhysicEdgeShape
- : public PhysicShape
+ class KGE_API EdgeShape
+ : public Shape
{
public:
- PhysicEdgeShape();
+ EdgeShape();
- PhysicEdgeShape(Point const& p1, Point const& p2);
+ EdgeShape(Point const& p1, Point const& p2);
void Set(Point const& p1, Point const& p2);
- void FitWorld(PhysicWorld* world) override;
+ void FitWorld(World* world) override;
protected:
Point p_[2];
@@ -120,17 +120,17 @@ namespace kiwano
};
// 链式形状
- class KGE_API PhysicChainShape
- : public PhysicShape
+ class KGE_API ChainShape
+ : public Shape
{
public:
- PhysicChainShape();
+ ChainShape();
- PhysicChainShape(Vector const& vertexs, bool loop = false);
+ ChainShape(Vector const& vertexs, bool loop = false);
void Set(Vector const& vertexs, bool loop = false);
- void FitWorld(PhysicWorld* world) override;
+ void FitWorld(World* world) override;
protected:
bool loop_;
diff --git a/src/kiwano-physics/World.cpp b/src/kiwano-physics/World.cpp
index 01ea268d..9a808a16 100644
--- a/src/kiwano-physics/World.cpp
+++ b/src/kiwano-physics/World.cpp
@@ -19,6 +19,7 @@
// THE SOFTWARE.
#include "World.h"
+#include
namespace kiwano
{
@@ -29,12 +30,12 @@ namespace kiwano
const float DefaultGlobalScale = 100.f; // 100 pixels per meters
}
- class PhysicWorld::DestructionListener : public b2DestructionListener
+ class World::DestructionListener : public b2DestructionListener
{
- PhysicWorld* world_;
+ World* world_;
public:
- DestructionListener(PhysicWorld* world)
+ DestructionListener(World* world)
: world_(world)
{
}
@@ -53,24 +54,34 @@ namespace kiwano
}
};
- class PhysicWorld::ContactListener
+ class World::ContactListener
: public b2ContactListener
{
- PhysicWorld* world_;
+ World* world_;
public:
- ContactListener(PhysicWorld* world)
+ ContactListener(World* world)
: world_(world)
{
}
- void BeginContact(b2Contact* contact) override { world_->OnContactBegin(contact); }
- void EndContact(b2Contact* contact) override { world_->OnContactEnd(contact); }
+ void BeginContact(b2Contact* contact) override
+ {
+ ContactBeginEvent evt(contact);
+ world_->Dispatch(&evt);
+ }
+
+ void EndContact(b2Contact* contact) override
+ {
+ ContactEndEvent evt(contact);
+ world_->Dispatch(&evt);
+ }
+
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold) override { KGE_NOT_USED(contact); KGE_NOT_USED(oldManifold); }
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse) override { KGE_NOT_USED(contact); KGE_NOT_USED(impulse); }
};
- PhysicWorld::PhysicWorld()
+ World::World()
: world_(b2Vec2(0, 10.0f))
, vel_iter_(6)
, pos_iter_(2)
@@ -86,7 +97,7 @@ namespace kiwano
world_.SetContactListener(contact_listener_);
}
- PhysicWorld::~PhysicWorld()
+ World::~World()
{
world_.SetDestructionListener(nullptr);
if (destruction_listener_)
@@ -102,15 +113,13 @@ namespace kiwano
contact_listener_ = nullptr;
}
- RemoveAllContactListeners();
-
// Make sure b2World was destroyed after b2Body
RemoveAllChildren();
RemoveAllBodies();
RemoveAllJoints();
}
- void PhysicWorld::RemoveBody(PhysicBody* body)
+ void World::RemoveBody(Body* body)
{
if (body && body->GetB2Body())
{
@@ -118,7 +127,7 @@ namespace kiwano
}
}
- void PhysicWorld::RemoveAllBodies()
+ void World::RemoveAllBodies()
{
if (world_.GetBodyCount())
{
@@ -132,7 +141,7 @@ namespace kiwano
}
}
- void PhysicWorld::AddJoint(PhysicJoint* joint)
+ void World::AddJoint(Joint* joint)
{
if (joint)
{
@@ -140,7 +149,7 @@ namespace kiwano
}
}
- void PhysicWorld::RemoveJoint(PhysicJoint* joint)
+ void World::RemoveJoint(Joint* joint)
{
if (joint)
{
@@ -159,7 +168,7 @@ namespace kiwano
}
}
- void PhysicWorld::RemoveAllJoints()
+ void World::RemoveAllJoints()
{
if (world_.GetJointCount())
{
@@ -178,14 +187,14 @@ namespace kiwano
joints_.clear();
}
- void PhysicWorld::JointRemoved(b2Joint* joint)
+ void World::JointRemoved(b2Joint* joint)
{
if (!removing_joint_ && joint)
{
auto iter = std::find_if(
joints_.begin(),
joints_.end(),
- [joint](PhysicJoint* j) -> bool { return j->GetB2Joint() == joint; }
+ [joint](Joint* j) -> bool { return j->GetB2Joint() == joint; }
);
if (iter != joints_.end())
@@ -195,36 +204,36 @@ namespace kiwano
}
}
- b2World* PhysicWorld::GetB2World()
+ b2World* World::GetB2World()
{
return &world_;
}
- const b2World* PhysicWorld::GetB2World() const
+ const b2World* World::GetB2World() const
{
return &world_;
}
- Vec2 PhysicWorld::GetGravity() const
+ Vec2 World::GetGravity() const
{
b2Vec2 g = world_.GetGravity();
return Vec2(g.x, g.y);
}
- void PhysicWorld::SetGravity(Vec2 gravity)
+ void World::SetGravity(Vec2 gravity)
{
world_.SetGravity(b2Vec2(gravity.x, gravity.y));
}
- void PhysicWorld::Update(Duration dt)
+ void World::Update(Duration dt)
{
Stage::Update(dt);
b2Body* b2body = world_.GetBodyList();
while (b2body)
{
- PhysicBody* body = static_cast(b2body->GetUserData());
- if (body && body->GetType() != PhysicBody::Type::Static)
+ Body* body = static_cast(b2body->GetUserData());
+ if (body && body->GetType() != Body::Type::Static)
{
body->UpdateFromActor();
}
@@ -237,8 +246,8 @@ namespace kiwano
b2body = world_.GetBodyList();
while (b2body)
{
- PhysicBody* body = static_cast(b2body->GetUserData());
- if (body && body->GetType() != PhysicBody::Type::Static)
+ Body* body = static_cast(b2body->GetUserData());
+ if (body && body->GetType() != Body::Type::Static)
{
body->UpdateActor();
}
diff --git a/src/kiwano-physics/World.h b/src/kiwano-physics/World.h
index 5cebada3..51bab4fb 100644
--- a/src/kiwano-physics/World.h
+++ b/src/kiwano-physics/World.h
@@ -21,24 +21,22 @@
#pragma once
#include
#include
-#include
namespace kiwano
{
namespace physics
{
// 物理世界
- class KGE_API PhysicWorld
+ class KGE_API World
: public Stage
- , public PhysicContactDispatcher
{
- friend class PhysicBody;
- friend class PhysicJoint;
+ friend class Body;
+ friend class Joint;
public:
- PhysicWorld();
+ World();
- virtual ~PhysicWorld();
+ virtual ~World();
// 获取重力
Vec2 GetGravity() const;
@@ -71,16 +69,16 @@ namespace kiwano
private:
// 移除物体
- void RemoveBody(PhysicBody* body);
+ void RemoveBody(Body* body);
// 移除所有物体
void RemoveAllBodies();
// 添加关节
- void AddJoint(PhysicJoint* joint);
+ void AddJoint(Joint* joint);
// 移除关节
- void RemoveJoint(PhysicJoint* joint);
+ void RemoveJoint(Joint* joint);
// 移除所有关节
void RemoveAllJoints();
@@ -105,9 +103,9 @@ namespace kiwano
ContactListener* contact_listener_;
bool removing_joint_;
- Vector joints_;
+ Vector joints_;
};
- KGE_DECLARE_SMART_PTR(PhysicWorld);
+ KGE_DECLARE_SMART_PTR(World);
}
}
diff --git a/src/kiwano-physics/kiwano-physics.h b/src/kiwano-physics/kiwano-physics.h
index 58f9cf29..fcc446d2 100644
--- a/src/kiwano-physics/kiwano-physics.h
+++ b/src/kiwano-physics/kiwano-physics.h
@@ -23,7 +23,7 @@
#include
#include
#include
-#include
+#include
#include
#include
#include
diff --git a/src/kiwano/2d/Actor.cpp b/src/kiwano/2d/Actor.cpp
index 100520c7..3570d728 100644
--- a/src/kiwano/2d/Actor.cpp
+++ b/src/kiwano/2d/Actor.cpp
@@ -20,7 +20,7 @@
#include
#include
-#include
+#include
#include
namespace kiwano
@@ -155,7 +155,7 @@ namespace kiwano
return visible_in_rt_;
}
- void Actor::Dispatch(Event& evt)
+ void Actor::Dispatch(Event* evt)
{
if (!visible_)
return;
@@ -167,21 +167,25 @@ namespace kiwano
child->Dispatch(evt);
}
- if (responsible_ && MouseEvent::Check(evt.type))
+ if (responsible_)
{
- if (evt.type == Event::MouseMove)
+ if (evt->type == event::MouseMove)
{
- if (!evt.target && ContainsPoint(Point{ evt.mouse.x, evt.mouse.y }))
+ auto mouse_evt = evt->SafeCast();
+ if (!mouse_evt->target && ContainsPoint(mouse_evt->pos))
{
- evt.target = this;
+ mouse_evt->target = this;
if (!hover_)
{
hover_ = true;
- Event hover = evt;
- hover.type = Event::MouseHover;
- EventDispatcher::Dispatch(hover);
+ MouseHoverEvent hover;
+ hover.pos = mouse_evt->pos;
+ hover.left_btn_down = mouse_evt->left_btn_down;
+ hover.right_btn_down = mouse_evt->right_btn_down;
+ hover.target = this;
+ EventDispatcher::Dispatch(&hover);
}
}
else if (hover_)
@@ -189,27 +193,34 @@ namespace kiwano
hover_ = false;
pressed_ = false;
- Event out = evt;
+ MouseOutEvent out;
+ out.pos = mouse_evt->pos;
+ out.left_btn_down = mouse_evt->left_btn_down;
+ out.right_btn_down = mouse_evt->right_btn_down;
out.target = this;
- out.type = Event::MouseOut;
- EventDispatcher::Dispatch(out);
+ EventDispatcher::Dispatch(&out);
}
}
- if (evt.type == Event::MouseBtnDown && hover_)
+ if (evt->type == event::MouseDown && hover_)
{
pressed_ = true;
- evt.target = this;
+ evt->SafeCast()->target = this;
}
- if (evt.type == Event::MouseBtnUp && pressed_)
+ if (evt->type == event::MouseUp && pressed_)
{
pressed_ = false;
- evt.target = this;
- Event click = evt;
- click.type = Event::Click;
- EventDispatcher::Dispatch(click);
+ auto mouse_up_evt = evt->SafeCast();
+ mouse_up_evt->target = this;
+
+ MouseOutEvent click;
+ click.pos = mouse_up_evt->pos;
+ click.left_btn_down = mouse_up_evt->left_btn_down;
+ click.right_btn_down = mouse_up_evt->right_btn_down;
+ click.target = this;
+ EventDispatcher::Dispatch(&click);
}
}
diff --git a/src/kiwano/2d/Actor.h b/src/kiwano/2d/Actor.h
index 6d805471..8b0e97fd 100644
--- a/src/kiwano/2d/Actor.h
+++ b/src/kiwano/2d/Actor.h
@@ -22,8 +22,8 @@
#include
#include
#include
-#include
-#include
+#include
+#include
namespace kiwano
{
@@ -49,109 +49,109 @@ namespace kiwano
Actor();
// 更新角色
- virtual void OnUpdate(Duration dt) { KGE_NOT_USED(dt); }
+ virtual void OnUpdate(Duration dt);
// 渲染角色
- virtual void OnRender(RenderTarget* rt) { KGE_NOT_USED(rt); }
+ virtual void OnRender(RenderTarget* rt);
// 获取显示状态
- bool IsVisible() const { return visible_; }
+ bool IsVisible() const;
// 获取响应状态
- bool IsResponsible() const { return responsible_; }
+ bool IsResponsible() const;
// 是否启用级联透明度
- bool IsCascadeOpacityEnabled() const { return cascade_opacity_; }
+ bool IsCascadeOpacityEnabled() const;
// 获取名称的 Hash 值
- size_t GetHashName() const { return hash_name_; }
+ size_t GetHashName() const;
// 获取 Z 轴顺序
- int GetZOrder() const { return z_order_; }
+ int GetZOrder() const;
// 获取坐标
- Point const& GetPosition() const { return transform_.position; }
+ Point const& GetPosition() const;
// 获取 x 坐标
- float GetPositionX() const { return GetPosition().x; }
+ float GetPositionX() const;
// 获取 y 坐标
- float GetPositionY() const { return GetPosition().y; }
+ float GetPositionY() const;
// 获取缩放比例
- Point const& GetScale() const { return transform_.scale; }
+ Point const& GetScale() const;
// 获取横向缩放比例
- float GetScaleX() const { return GetScale().x; }
+ float GetScaleX() const;
// 获取纵向缩放比例
- float GetScaleY() const { return GetScale().y; }
+ float GetScaleY() const;
// 获取错切角度
- Point const& GetSkew() const { return transform_.skew; }
+ Point const& GetSkew() const;
// 获取横向错切角度
- float GetSkewX() const { return GetSkew().x; }
+ float GetSkewX() const;
// 获取纵向错切角度
- float GetSkewY() const { return GetSkew().y; }
+ float GetSkewY() const;
// 获取旋转角度
- float GetRotation() const { return transform_.rotation; }
+ float GetRotation() const;
// 获取宽度
- float GetWidth() const { return GetSize().x; }
+ float GetWidth() const;
// 获取高度
- float GetHeight() const { return GetSize().y; }
+ float GetHeight() const;
// 获取大小
- Size const& GetSize() const { return size_; }
+ Size const& GetSize() const;
// 获取缩放后的宽度
- float GetScaledWidth() const { return GetWidth() * GetScaleX(); }
+ float GetScaledWidth() const;
// 获取缩放后的高度
- float GetScaledHeight() const { return GetHeight() * GetScaleY(); }
+ float GetScaledHeight() const;
// 获取缩放后的大小
- Size GetScaledSize() const { return Size{ GetScaledWidth(), GetScaledHeight() }; }
+ Size GetScaledSize() const;
// 获取锚点
- Point const& GetAnchor() const { return anchor_; }
+ Point const& GetAnchor() const;
// 获取 x 方向锚点
- float GetAnchorX() const { return GetAnchor().x; }
+ float GetAnchorX() const;
// 获取 y 方向锚点
- float GetAnchorY() const { return GetAnchor().y; }
+ float GetAnchorY() const;
// 获取透明度
- float GetOpacity() const { return opacity_; }
+ float GetOpacity() const;
// 获取显示透明度
- float GetDisplayedOpacity() const { return displayed_opacity_; }
+ float GetDisplayedOpacity() const;
// 获取变换
- Transform GetTransform() const { return transform_; }
+ Transform GetTransform() const;
// 获取父角色
- inline Actor* GetParent() const { return parent_; }
+ Actor* GetParent() const;
// 获取所在舞台
- inline Stage* GetStage() const { return stage_; }
+ Stage* GetStage() const;
// 获取边框
- virtual Rect GetBounds() const;
+ virtual Rect GetBounds() const;
// 获取外切包围盒
- virtual Rect GetBoundingBox() const;
+ virtual Rect GetBoundingBox() const;
// 获取二维变换矩阵
- Matrix3x2 const& GetTransformMatrix() const;
+ Matrix3x2 const& GetTransformMatrix() const;
// 获取二维变换的逆矩阵
- Matrix3x2 const& GetTransformInverseMatrix() const;
+ Matrix3x2 const& GetTransformInverseMatrix() const;
// 设置是否显示
void SetVisible(
@@ -169,13 +169,10 @@ namespace kiwano
);
// 设置坐标
- inline void SetPosition(
+ void SetPosition(
float x,
float y
- )
- {
- SetPosition(Point{ x, y });
- }
+ );
// 设置横坐标
void SetPositionX(
@@ -193,13 +190,10 @@ namespace kiwano
);
// 移动坐标
- inline void Move(
+ void Move(
float vx,
float vy
- )
- {
- Move(Vec2{ vx, vy });
- }
+ );
// 设置缩放比例
// 默认为 (1.0, 1.0)
@@ -209,13 +203,10 @@ namespace kiwano
// 设置缩放比例
// 默认为 (1.0, 1.0)
- inline void SetScale(
+ void SetScale(
float scalex,
float scaley
- )
- {
- SetScale(Vec2{ scalex, scaley });
- }
+ );
// 设置错切角度
// 默认为 (0, 0)
@@ -225,13 +216,10 @@ namespace kiwano
// 设置错切角度
// 默认为 (0, 0)
- inline void SetSkew(
+ void SetSkew(
float skewx,
float skewy
- )
- {
- SetSkew(Vec2{ skewx, skewy });
- }
+ );
// 设置旋转角度
// 默认为 0
@@ -247,13 +235,10 @@ namespace kiwano
// 设置锚点位置
// 默认为 (0, 0), 范围 [0, 1]
- inline void SetAnchor(
+ void SetAnchor(
float anchorx,
float anchory
- )
- {
- SetAnchor(Vec2{ anchorx, anchory });
- }
+ );
// 修改宽度
virtual void SetWidth(
@@ -271,13 +256,10 @@ namespace kiwano
);
// 修改大小
- inline void SetSize(
+ void SetSize(
float width,
float height
- )
- {
- SetSize(Size{ width, height });
- }
+ );
// 设置透明度
// 默认为 1.0, 范围 [0, 1]
@@ -364,8 +346,26 @@ namespace kiwano
// 判断点是否在角色内
virtual bool ContainsPoint(const Point& point) const;
+ // 暂停角色更新
+ void PauseUpdating();
+
+ // 继续角色更新
+ void ResumeUpdating();
+
+ // 角色更新是否暂停
+ bool IsUpdatePausing() const;
+
+ // 设置更新时的回调函数
+ void SetCallbackOnUpdate(UpdateCallback const& cb);
+
+ // 获取更新时的回调函数
+ UpdateCallback GetCallbackOnUpdate() const;
+
+ // 渲染角色边界
+ void ShowBorder(bool show);
+
// 事件分发
- void Dispatch(Event& evt) override;
+ void Dispatch(Event* evt) override;
// 设置默认锚点
static void SetDefaultAnchor(
@@ -373,24 +373,6 @@ namespace kiwano
float anchor_y
);
- // 暂停角色更新
- inline void PauseUpdating() { update_pausing_ = true; }
-
- // 继续角色更新
- inline void ResumeUpdating() { update_pausing_ = false; }
-
- // 角色更新是否暂停
- inline bool IsUpdatePausing() const { return update_pausing_; }
-
- // 设置更新时的回调函数
- inline void SetCallbackOnUpdate(UpdateCallback const& cb) { cb_update_ = cb; }
-
- // 获取更新时的回调函数
- inline UpdateCallback GetCallbackOnUpdate() const { return cb_update_; }
-
- // 渲染角色边界
- inline void ShowBorder(bool show) { show_border_ = show; }
-
protected:
virtual void Update(Duration dt);
@@ -439,4 +421,219 @@ namespace kiwano
mutable Matrix3x2 transform_matrix_inverse_;
};
+ inline void Actor::OnUpdate(Duration dt)
+ {
+ KGE_NOT_USED(dt);
+ }
+
+ inline void Actor::OnRender(RenderTarget* rt)
+ {
+ KGE_NOT_USED(rt);
+ }
+
+ inline bool Actor::IsVisible() const
+ {
+ return visible_;
+ }
+
+ inline bool Actor::IsResponsible() const
+ {
+ return responsible_;
+ }
+
+ inline bool Actor::IsCascadeOpacityEnabled() const
+ {
+ return cascade_opacity_;
+ }
+
+ inline size_t Actor::GetHashName() const
+ {
+ return hash_name_;
+ }
+
+ inline int Actor::GetZOrder() const
+ {
+ return z_order_;
+ }
+
+ inline Point const& Actor::GetPosition() const
+ {
+ return transform_.position;
+ }
+
+ inline float Actor::GetPositionX() const
+ {
+ return GetPosition().x;
+ }
+
+ inline float Actor::GetPositionY() const
+ {
+ return GetPosition().y;
+ }
+
+ inline Point const& Actor::GetScale() const
+ {
+ return transform_.scale;
+ }
+
+ inline float Actor::GetScaleX() const
+ {
+ return GetScale().x;
+ }
+
+ inline float Actor::GetScaleY() const
+ {
+ return GetScale().y;
+ }
+
+ inline Point const& Actor::GetSkew() const
+ {
+ return transform_.skew;
+ }
+
+ inline float Actor::GetSkewX() const
+ {
+ return GetSkew().x;
+ }
+
+ inline float Actor::GetSkewY() const
+ {
+ return GetSkew().y;
+ }
+
+ inline float Actor::GetRotation() const
+ {
+ return transform_.rotation;
+ }
+
+ inline float Actor::GetWidth() const
+ {
+ return GetSize().x;
+ }
+
+ inline float Actor::GetHeight() const
+ {
+ return GetSize().y;
+ }
+
+ inline Size const& Actor::GetSize() const
+ {
+ return size_;
+ }
+
+ inline float Actor::GetScaledWidth() const
+ {
+ return GetWidth() * GetScaleX();
+ }
+
+ inline float Actor::GetScaledHeight() const
+ {
+ return GetHeight() * GetScaleY();
+ }
+
+ inline Size Actor::GetScaledSize() const
+ {
+ return Size{ GetScaledWidth(), GetScaledHeight() };
+ }
+
+ inline Point const& Actor::GetAnchor() const
+ {
+ return anchor_;
+ }
+
+ inline float Actor::GetAnchorX() const
+ {
+ return GetAnchor().x;
+ }
+
+ inline float Actor::GetAnchorY() const
+ {
+ return GetAnchor().y;
+ }
+
+ inline float Actor::GetOpacity() const
+ {
+ return opacity_;
+ }
+
+ inline float Actor::GetDisplayedOpacity() const
+ {
+ return displayed_opacity_;
+ }
+
+ inline Transform Actor::GetTransform() const
+ {
+ return transform_;
+ }
+
+ inline Actor* Actor::GetParent() const
+ {
+ return parent_;
+ }
+
+ inline Stage* Actor::GetStage() const
+ {
+ return stage_;
+ }
+
+ inline void Actor::PauseUpdating()
+ {
+ update_pausing_ = true;
+ }
+
+ inline void Actor::ResumeUpdating()
+ {
+ update_pausing_ = false;
+ }
+
+ inline bool Actor::IsUpdatePausing() const
+ {
+ return update_pausing_;
+ }
+
+ inline void Actor::SetCallbackOnUpdate(UpdateCallback const& cb)
+ {
+ cb_update_ = cb;
+ }
+
+ inline Actor::UpdateCallback Actor::GetCallbackOnUpdate() const
+ {
+ return cb_update_;
+ }
+
+ inline void Actor::ShowBorder(bool show)
+ {
+ show_border_ = show;
+ }
+
+ inline void Actor::SetPosition(float x, float y)
+ {
+ SetPosition(Point{ x, y });
+ }
+
+ inline void Actor::Move(float vx, float vy)
+ {
+ Move(Vec2{ vx, vy });
+ }
+
+ inline void Actor::SetScale(float scalex, float scaley)
+ {
+ SetScale(Vec2{ scalex, scaley });
+ }
+
+ inline void Actor::SetAnchor(float anchorx, float anchory)
+ {
+ SetAnchor(Vec2{ anchorx, anchory });
+ }
+
+ inline void Actor::SetSize(float width, float height)
+ {
+ SetSize(Size{ width, height });
+ }
+
+ inline void Actor::SetSkew(float skewx, float skewy)
+ {
+ SetSkew(Vec2{ skewx, skewy });
+ }
+
}
diff --git a/src/kiwano/2d/Canvas.cpp b/src/kiwano/2d/Canvas.cpp
index c4852768..cbb6b60e 100644
--- a/src/kiwano/2d/Canvas.cpp
+++ b/src/kiwano/2d/Canvas.cpp
@@ -19,7 +19,7 @@
// THE SOFTWARE.
#include
-#include
+#include
#include
namespace kiwano
diff --git a/src/kiwano/2d/DebugActor.cpp b/src/kiwano/2d/DebugActor.cpp
index 65dc2900..5d53e1fa 100644
--- a/src/kiwano/2d/DebugActor.cpp
+++ b/src/kiwano/2d/DebugActor.cpp
@@ -66,8 +66,8 @@ namespace kiwano
style.line_spacing = 20.f;
debug_text_->SetStyle(style);
- AddListener(Event::MouseHover, [=](const Event&) { SetOpacity(0.4f); });
- AddListener(Event::MouseOut, [=](const Event&) { SetOpacity(1.f); });
+ AddListener(event::MouseHover, [=](Event*) { SetOpacity(0.4f); });
+ AddListener(event::MouseOut, [=](Event*) { SetOpacity(1.f); });
}
DebugActor::~DebugActor()
@@ -87,7 +87,7 @@ namespace kiwano
KGE_NOT_USED(dt);
frame_time_.push_back(Time::Now());
- while (frame_time_.back() - frame_time_.front() >= time::Sec)
+ while (frame_time_.back() - frame_time_.front() >= Duration::Second)
{
frame_time_.erase(frame_time_.begin());
}
diff --git a/src/kiwano/2d/Frame.h b/src/kiwano/2d/Frame.h
index 881b3c05..f9b1a947 100644
--- a/src/kiwano/2d/Frame.h
+++ b/src/kiwano/2d/Frame.h
@@ -19,7 +19,7 @@
// THE SOFTWARE.
#pragma once
-#include
+#include
#include
namespace kiwano
diff --git a/src/kiwano/2d/FrameSequence.cpp b/src/kiwano/2d/FrameSequence.cpp
index 0bc00b5e..c72e2d01 100644
--- a/src/kiwano/2d/FrameSequence.cpp
+++ b/src/kiwano/2d/FrameSequence.cpp
@@ -20,7 +20,7 @@
#include
#include
-#include
+#include
namespace kiwano
{
diff --git a/src/kiwano/2d/GifSprite.cpp b/src/kiwano/2d/GifSprite.cpp
index 1ff49add..b8dc4e64 100644
--- a/src/kiwano/2d/GifSprite.cpp
+++ b/src/kiwano/2d/GifSprite.cpp
@@ -19,7 +19,7 @@
// THE SOFTWARE.
#include
-#include
+#include
#include
#include
diff --git a/src/kiwano/2d/GifSprite.h b/src/kiwano/2d/GifSprite.h
index bc5c4cb8..10ebb933 100644
--- a/src/kiwano/2d/GifSprite.h
+++ b/src/kiwano/2d/GifSprite.h
@@ -20,7 +20,7 @@
#pragma once
#include
-#include
+#include
#include
#include
diff --git a/src/kiwano/2d/Layer.cpp b/src/kiwano/2d/Layer.cpp
index 8a01bc63..270c50a7 100644
--- a/src/kiwano/2d/Layer.cpp
+++ b/src/kiwano/2d/Layer.cpp
@@ -29,14 +29,14 @@ namespace kiwano
{
auto handler = Closure(this, &Layer::HandleMessages);
- AddListener(Event::MouseBtnDown, handler);
- AddListener(Event::MouseBtnUp, handler);
- AddListener(Event::MouseMove, handler);
- AddListener(Event::MouseWheel, handler);
+ AddListener(event::MouseDown, handler);
+ AddListener(event::MouseUp, handler);
+ AddListener(event::MouseMove, handler);
+ AddListener(event::MouseWheel, handler);
- AddListener(Event::KeyDown, handler);
- AddListener(Event::KeyUp, handler);
- AddListener(Event::Char, handler);
+ AddListener(event::KeyDown, handler);
+ AddListener(event::KeyUp, handler);
+ AddListener(event::KeyChar, handler);
}
Layer::~Layer()
@@ -64,7 +64,7 @@ namespace kiwano
area_.SetMaskTransform(transform);
}
- void Layer::Dispatch(Event& evt)
+ void Layer::Dispatch(Event* evt)
{
if (!IsVisible())
return;
@@ -91,31 +91,42 @@ namespace kiwano
rt->PopLayer();
}
- void Layer::HandleMessages(Event const& evt)
+ void Layer::HandleMessages(Event* evt)
{
- switch (evt.type)
+ if (evt->type == event::MouseDown)
{
- case Event::MouseBtnDown:
- OnMouseButtonDown(evt.mouse.button, Point{ evt.mouse.x, evt.mouse.y });
- break;
- case Event::MouseBtnUp:
- OnMouseButtonUp(evt.mouse.button, Point{ evt.mouse.x, evt.mouse.y });
- break;
- case Event::MouseMove:
- OnMouseMoved(Point{ evt.mouse.x, evt.mouse.y });
- break;
- case Event::MouseWheel:
- OnMouseWheel(evt.mouse.wheel);
- break;
- case Event::KeyDown:
- OnKeyDown(evt.key.code);
- break;
- case Event::KeyUp:
- OnKeyUp(evt.key.code);
- break;
- case Event::Char:
- OnChar(evt.key.c);
- break;
+ auto real_evt = evt->SafeCast