diff --git a/src/kiwano/2d/action/Action.cpp b/src/kiwano/2d/action/Action.cpp index 47b11755..fd1d5a6c 100644 --- a/src/kiwano/2d/action/Action.cpp +++ b/src/kiwano/2d/action/Action.cpp @@ -51,8 +51,8 @@ namespace kiwano if (status_ == Status::NotStarted) { - Init(target); status_ = delay_.IsZero() ? Status::Started : Status::Delayed; + Init(target); } switch (status_) diff --git a/src/kiwano/2d/action/ActionWalk.cpp b/src/kiwano/2d/action/ActionWalk.cpp index c6153ce5..41f61ffe 100644 --- a/src/kiwano/2d/action/ActionWalk.cpp +++ b/src/kiwano/2d/action/ActionWalk.cpp @@ -62,7 +62,7 @@ namespace kiwano { if (!path_) { - Complete(target); + Done(); return; } diff --git a/src/kiwano/2d/action/Animation.cpp b/src/kiwano/2d/action/Animation.cpp index 12869a4b..5c5dd0f4 100644 --- a/src/kiwano/2d/action/Animation.cpp +++ b/src/kiwano/2d/action/Animation.cpp @@ -52,6 +52,7 @@ namespace kiwano void Animation::Init(ActorPtr target) { + KGE_ASSERT(frame_seq_ && "Animation::Init() failed: FrameSequence is NULL!"); if (!frame_seq_ || frame_seq_->GetFrames().empty()) { Done(); @@ -59,6 +60,8 @@ namespace kiwano } auto sprite_target = dynamic_cast(target.get()); + KGE_ASSERT(sprite_target && "Animation only supports Sprites!"); + if (sprite_target && frame_seq_) { sprite_target->SetFrame(frame_seq_->GetFrames()[0]); @@ -69,13 +72,14 @@ namespace kiwano { auto sprite_target = dynamic_cast(target.get()); - KGE_ASSERT(sprite_target && "Animation only supports Sprites"); + if (sprite_target && frame_seq_) + { + const auto& frames = frame_seq_->GetFrames(); + auto size = frames.size(); + auto index = std::min(static_cast(math::Floor(size * percent)), size - 1); - const auto& frames = frame_seq_->GetFrames(); - auto size = frames.size(); - auto index = std::min(static_cast(math::Floor(size * percent)), size - 1); - - sprite_target->SetFrame(frames[index]); + sprite_target->SetFrame(frames[index]); + } } ActionPtr Animation::Clone() const diff --git a/src/kiwano/config.h b/src/kiwano/config.h index c93cd824..9d562a56 100644 --- a/src/kiwano/config.h +++ b/src/kiwano/config.h @@ -19,3 +19,6 @@ //---- Define DirectX version. Defaults to using Direct3D11 //#define KGE_USE_DIRECTX10 + +//---- Define to enable DirectX debug layer +//#define KGE_ENABLE_DX_DEBUG diff --git a/src/kiwano/renderer/win32/D2DDeviceResources.cpp b/src/kiwano/renderer/win32/D2DDeviceResources.cpp index b4534e77..550fb3f5 100644 --- a/src/kiwano/renderer/win32/D2DDeviceResources.cpp +++ b/src/kiwano/renderer/win32/D2DDeviceResources.cpp @@ -191,7 +191,7 @@ namespace kiwano D2D1_FACTORY_OPTIONS options; ZeroMemory(&options, sizeof(D2D1_FACTORY_OPTIONS)); -#ifdef KGE_DEBUG +#if defined(KGE_DEBUG) && defined(KGE_ENABLE_DX_DEBUG) options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION; #endif diff --git a/src/kiwano/renderer/win32/D3D10DeviceResources.cpp b/src/kiwano/renderer/win32/D3D10DeviceResources.cpp index 9278893c..59e4dfbe 100644 --- a/src/kiwano/renderer/win32/D3D10DeviceResources.cpp +++ b/src/kiwano/renderer/win32/D3D10DeviceResources.cpp @@ -217,7 +217,7 @@ namespace kiwano // than the API default. It is required for compatibility with Direct2D. UInt32 creation_flags = D3D10_CREATE_DEVICE_BGRA_SUPPORT; -#if defined(KGE_DEBUG) +#if defined(KGE_DEBUG) && defined(KGE_ENABLE_DX_DEBUG) if (DX::SdkLayersAvailable()) { creation_flags |= D3D10_CREATE_DEVICE_DEBUG; diff --git a/src/kiwano/renderer/win32/D3D11DeviceResources.cpp b/src/kiwano/renderer/win32/D3D11DeviceResources.cpp index 801ce3bb..11e64378 100644 --- a/src/kiwano/renderer/win32/D3D11DeviceResources.cpp +++ b/src/kiwano/renderer/win32/D3D11DeviceResources.cpp @@ -209,7 +209,7 @@ namespace kiwano // than the API default. It is required for compatibility with Direct2D. UInt32 creation_flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; -#if defined(KGE_DEBUG) +#if defined(KGE_DEBUG) && defined(KGE_ENABLE_DX_DEBUG) if (DX::SdkLayersAvailable()) { creation_flags |= D3D11_CREATE_DEVICE_DEBUG; diff --git a/src/kiwano/utils/ResourceCache.cpp b/src/kiwano/utils/ResourceCache.cpp index 324c0d69..c016d362 100644 --- a/src/kiwano/utils/ResourceCache.cpp +++ b/src/kiwano/utils/ResourceCache.cpp @@ -201,8 +201,8 @@ namespace kiwano if (files.empty()) return 0; - Vector texture_arr; - texture_arr.reserve(files.size()); + Vector frames; + frames.reserve(files.size()); for (const auto& file : files) { @@ -211,15 +211,15 @@ namespace kiwano { if (ptr->Load(file)) { - texture_arr.push_back(ptr); + frames.push_back(ptr); } } } - if (!texture_arr.empty()) + if (!frames.empty()) { - FrameSequencePtr frames = new (std::nothrow) FrameSequence(texture_arr); - return AddFrameSequence(id, frames); + FrameSequencePtr fs = new (std::nothrow) FrameSequence(frames); + return AddFrameSequence(id, fs); } return 0; } @@ -238,8 +238,8 @@ namespace kiwano Float32 width = raw_width / cols; Float32 height = raw_height / rows; - Vector texture_arr; - texture_arr.reserve(rows * cols); + Vector frames; + frames.reserve(rows * cols); for (Int32 i = 0; i < rows; i++) { @@ -249,13 +249,13 @@ namespace kiwano if (ptr) { ptr->SetCropRect(Rect{ j * width, i * height, (j + 1) * width, (i + 1) * height }); - texture_arr.push_back(ptr); + frames.push_back(ptr); } } } - FrameSequencePtr frames = new (std::nothrow) FrameSequence(texture_arr); - return AddFrameSequence(id, frames); + FrameSequencePtr fs = new (std::nothrow) FrameSequence(frames); + return AddFrameSequence(id, fs); } UInt32 ResourceCache::AddFrameSequence(String const & id, FrameSequencePtr frames) @@ -325,7 +325,7 @@ namespace kiwano } else { - // Simple texture + // Simple image return loader->AddFrame(*id, gdata->path + (*file)); } } @@ -358,24 +358,24 @@ namespace kiwano global_data.path = json_data[L"path"]; } - if (json_data.count(L"textures")) + if (json_data.count(L"images")) { - for (const auto& texture : json_data[L"textures"]) + for (const auto& image : json_data[L"images"]) { const String* id = nullptr, * type = nullptr, * file = nullptr; Int32 rows = 0, cols = 0; - if (texture.count(L"id")) id = &texture[L"id"].as_string(); - if (texture.count(L"type")) type = &texture[L"type"].as_string(); - if (texture.count(L"file")) file = &texture[L"file"].as_string(); - if (texture.count(L"rows")) rows = texture[L"rows"].as_int(); - if (texture.count(L"cols")) cols = texture[L"cols"].as_int(); + if (image.count(L"id")) id = &image[L"id"].as_string(); + if (image.count(L"type")) type = &image[L"type"].as_string(); + if (image.count(L"file")) file = &image[L"file"].as_string(); + if (image.count(L"rows")) rows = image[L"rows"].as_int(); + if (image.count(L"cols")) cols = image[L"cols"].as_int(); - if (texture.count(L"files")) + if (image.count(L"files")) { Vector files; - files.reserve(texture[L"files"].size()); - for (const auto& file : texture[L"files"]) + files.reserve(image[L"files"].size()); + for (const auto& file : image[L"files"]) { files.push_back(file.as_string().c_str()); } @@ -400,23 +400,23 @@ namespace kiwano global_data.path = path->GetText(); } - if (auto textures = elem->FirstChildElement(L"textures")) + if (auto images = elem->FirstChildElement(L"images")) { - for (auto texture = textures->FirstChildElement(); texture; texture = texture->NextSiblingElement()) + for (auto image = images->FirstChildElement(); image; image = image->NextSiblingElement()) { String id, type, file; Int32 rows = 0, cols = 0; - if (auto attr = texture->Attribute(L"id")) id.assign(attr); // assign() copies attr content - if (auto attr = texture->Attribute(L"type")) type = attr; // operator=() just holds attr pointer - if (auto attr = texture->Attribute(L"file")) file = attr; - if (auto attr = texture->IntAttribute(L"rows")) rows = attr; - if (auto attr = texture->IntAttribute(L"cols")) cols = attr; + if (auto attr = image->Attribute(L"id")) id.assign(attr); // assign() copies attr content + if (auto attr = image->Attribute(L"type")) type = attr; // operator=() just holds attr pointer + if (auto attr = image->Attribute(L"file")) file = attr; + if (auto attr = image->IntAttribute(L"rows")) rows = attr; + if (auto attr = image->IntAttribute(L"cols")) cols = attr; - if (file.empty() && !texture->NoChildren()) + if (file.empty() && !image->NoChildren()) { Vector files_arr; - for (auto file = texture->FirstChildElement(); file; file = file->NextSiblingElement()) + for (auto file = image->FirstChildElement(); file; file = file->NextSiblingElement()) { if (auto path = file->Attribute(L"path")) {