2018-11-19 19:32:12 +08:00
|
|
|
// Copyright (c) 2016-2018 Easy2D - 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.
|
|
|
|
|
|
2018-11-23 14:55:03 +08:00
|
|
|
#include "DebugNode.h"
|
|
|
|
|
#include "render.h"
|
2018-11-19 19:32:12 +08:00
|
|
|
#include "../utils/string.h"
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <psapi.h>
|
|
|
|
|
|
|
|
|
|
#pragma comment(lib, "psapi.lib")
|
|
|
|
|
|
|
|
|
|
namespace easy2d
|
|
|
|
|
{
|
2019-01-24 12:21:01 +08:00
|
|
|
DebugNode::DebugNode()
|
2018-11-19 19:32:12 +08:00
|
|
|
{
|
|
|
|
|
debug_text_ = new Text();
|
2018-11-23 14:55:03 +08:00
|
|
|
debug_text_->SetPosition(15, 15);
|
2018-11-19 19:32:12 +08:00
|
|
|
this->AddChild(debug_text_);
|
|
|
|
|
|
|
|
|
|
Font font;
|
|
|
|
|
font.size = 16.f;
|
|
|
|
|
font.weight = FontWeight::Normal;
|
|
|
|
|
debug_text_->SetFont(font);
|
|
|
|
|
|
|
|
|
|
TextStyle style;
|
|
|
|
|
style.wrap = false;
|
2018-11-23 14:55:03 +08:00
|
|
|
style.line_spacing = 20.f;
|
2018-11-19 19:32:12 +08:00
|
|
|
debug_text_->SetStyle(style);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-24 12:21:01 +08:00
|
|
|
DebugNode::~DebugNode()
|
2018-11-19 19:32:12 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-24 12:21:01 +08:00
|
|
|
void DebugNode::AddDebugText(String const & text)
|
2018-11-19 19:32:12 +08:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
texts_.push_back(text);
|
|
|
|
|
}
|
|
|
|
|
catch (...)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-24 12:21:01 +08:00
|
|
|
void DebugNode::ClearDebugText()
|
2018-11-19 19:32:12 +08:00
|
|
|
{
|
|
|
|
|
texts_.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-24 12:21:01 +08:00
|
|
|
void DebugNode::OnRender()
|
2018-11-23 14:55:03 +08:00
|
|
|
{
|
2019-01-24 12:21:01 +08:00
|
|
|
auto rt = RenderSystem::Instance();
|
2018-11-23 14:55:03 +08:00
|
|
|
|
2019-01-24 12:21:01 +08:00
|
|
|
rt->GetSolidBrush()->SetColor(Color(0.0f, 0.0f, 0.0f, 0.5f));
|
2018-11-23 14:55:03 +08:00
|
|
|
|
2019-01-24 12:21:01 +08:00
|
|
|
rt->GetRenderTarget()->FillRoundedRectangle(
|
2018-11-23 14:55:03 +08:00
|
|
|
D2D1::RoundedRect(
|
|
|
|
|
D2D1_RECT_F{ 10, 10, 200, 120 },
|
|
|
|
|
6.f,
|
|
|
|
|
6.f),
|
2019-01-24 12:21:01 +08:00
|
|
|
rt->GetSolidBrush().Get()
|
2018-11-23 14:55:03 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-24 15:14:55 +08:00
|
|
|
void DebugNode::OnUpdate(Duration dt)
|
2018-11-19 19:32:12 +08:00
|
|
|
{
|
2019-02-03 00:16:53 +08:00
|
|
|
E2D_NOT_USED(dt);
|
|
|
|
|
|
2018-11-19 19:32:12 +08:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
frame_time_.push_back(time::Now());
|
|
|
|
|
while (frame_time_.back() - frame_time_.front() >= time::Second)
|
|
|
|
|
{
|
|
|
|
|
frame_time_.erase(frame_time_.begin());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (std::exception& e)
|
|
|
|
|
{
|
|
|
|
|
debug_text_->SetText(StringMultiByteToWideChar(e.what()));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::wstringstream ss;
|
2018-11-23 14:55:03 +08:00
|
|
|
ss << "Fps: " << frame_time_.size() << std::endl;
|
2018-11-19 19:32:12 +08:00
|
|
|
|
2018-11-19 20:11:02 +08:00
|
|
|
#ifdef E2D_DEBUG
|
2018-11-23 14:55:03 +08:00
|
|
|
ss << "Objects: " << Object::__GetTracingObjects().size() << std::endl;
|
|
|
|
|
#endif
|
2018-11-19 20:11:02 +08:00
|
|
|
|
2019-01-24 12:21:01 +08:00
|
|
|
ss << "Render: " << RenderSystem::Instance()->GetStatus().duration.Milliseconds() << "ms" << std::endl;
|
2018-11-19 20:11:02 +08:00
|
|
|
|
2019-01-24 12:21:01 +08:00
|
|
|
ss << "Primitives / sec: " << RenderSystem::Instance()->GetStatus().primitives * frame_time_.size() << std::endl;
|
2018-11-19 20:11:02 +08:00
|
|
|
|
2018-11-19 19:32:12 +08:00
|
|
|
PROCESS_MEMORY_COUNTERS_EX pmc;
|
|
|
|
|
GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc));
|
2018-11-23 14:55:03 +08:00
|
|
|
ss << "Memory: " << pmc.PrivateUsage / 1024 << "kb";
|
2018-11-19 19:32:12 +08:00
|
|
|
|
|
|
|
|
for (const auto& text : texts_)
|
2018-11-19 20:11:02 +08:00
|
|
|
ss << std::endl << text;
|
2018-11-19 19:32:12 +08:00
|
|
|
|
|
|
|
|
debug_text_->SetText(ss.str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|