| 
									
										
										
										
											2019-04-11 14:40:54 +08:00
										 |  |  | // Copyright (c) 2016-2018 Kiwano - Nomango
 | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | // 
 | 
					
						
							|  |  |  | // 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.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 23:21:20 +08:00
										 |  |  | #include "DebugActor.h"
 | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | #include "Text.h"
 | 
					
						
							|  |  |  | #include "../renderer/render.h"
 | 
					
						
							|  |  |  | #include <sstream>
 | 
					
						
							|  |  |  | #include <psapi.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma comment(lib, "psapi.lib")
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-11 14:40:54 +08:00
										 |  |  | namespace kiwano | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	DebugNode::DebugNode() | 
					
						
							| 
									
										
										
										
											2019-08-03 23:28:45 +08:00
										 |  |  | 		: background_color_(0.0f, 0.0f, 0.0f, 0.7f) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-08-13 21:16:38 +08:00
										 |  |  | 		SetName(L"kiwano-debug-actor"); | 
					
						
							| 
									
										
										
										
											2019-08-03 23:28:45 +08:00
										 |  |  | 		SetPosition(10, 10); | 
					
						
							|  |  |  | 		SetResponsible(true); | 
					
						
							|  |  |  | 		SetCascadeOpacityEnabled(true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-02 13:57:17 +08:00
										 |  |  | 		debug_text_ = new Text; | 
					
						
							| 
									
										
										
										
											2019-08-03 23:28:45 +08:00
										 |  |  | 		debug_text_->SetPosition(10, 10); | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +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; | 
					
						
							|  |  |  | 		style.line_spacing = 20.f; | 
					
						
							|  |  |  | 		debug_text_->SetStyle(style); | 
					
						
							| 
									
										
										
										
											2019-08-03 23:28:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-05 00:12:47 +08:00
										 |  |  | 		AddListener(Event::MouseHover, [=](const Event&) { SetOpacity(0.4f); }); | 
					
						
							| 
									
										
										
										
											2019-08-03 23:28:45 +08:00
										 |  |  | 		AddListener(Event::MouseOut, [=](const Event&) { SetOpacity(1.f); }); | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	DebugNode::~DebugNode() | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void DebugNode::OnRender() | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-08-13 15:00:43 +08:00
										 |  |  | 		auto renderer = Renderer::GetInstance(); | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-05 09:07:58 +08:00
										 |  |  | 		renderer->GetSolidColorBrush()->SetColor(DX::ConvertToColorF(background_color_)); | 
					
						
							|  |  |  | 		renderer->GetD2DDeviceResources()->GetDeviceContext()->FillRoundedRectangle( | 
					
						
							| 
									
										
										
										
											2019-08-03 23:28:45 +08:00
										 |  |  | 			D2D1::RoundedRect(DX::ConvertToRectF(GetBounds()), 5.f, 5.f), | 
					
						
							| 
									
										
										
										
											2019-08-05 09:07:58 +08:00
										 |  |  | 			renderer->GetSolidColorBrush() | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void DebugNode::OnUpdate(Duration dt) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-08-12 14:51:54 +08:00
										 |  |  | 		KGE_UNUSED(dt); | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-09 02:25:17 +08:00
										 |  |  | 		frame_time_.push_back(Time::Now()); | 
					
						
							|  |  |  | 		while (frame_time_.back() - frame_time_.front() >= time::Sec) | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			frame_time_.erase(frame_time_.begin()); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		std::wstringstream ss; | 
					
						
							|  |  |  | 		ss << "Fps: " << frame_time_.size() << std::endl; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-03 23:28:45 +08:00
										 |  |  | #if defined(KGE_DEBUG)
 | 
					
						
							|  |  |  | 		if (Object::IsTracingLeaks()) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			ss << "Objects: " << Object::__GetTracingObjects().size() << std::endl; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 15:00:43 +08:00
										 |  |  | 		ss << "Render: " << Renderer::GetInstance()->GetStatus().duration.Milliseconds() << "ms" << std::endl; | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 15:00:43 +08:00
										 |  |  | 		ss << "Primitives / sec: " << Renderer::GetInstance()->GetStatus().primitives * frame_time_.size() << std::endl; | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		PROCESS_MEMORY_COUNTERS_EX pmc; | 
					
						
							|  |  |  | 		GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc)); | 
					
						
							|  |  |  | 		ss << "Memory: " << pmc.PrivateUsage / 1024 << "kb"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		debug_text_->SetText(ss.str()); | 
					
						
							| 
									
										
										
										
											2019-08-03 23:28:45 +08:00
										 |  |  | 		SetSize(Size{ 20 + debug_text_->GetLayoutSize().x, 20 + debug_text_->GetLayoutSize().y }); | 
					
						
							| 
									
										
										
										
											2019-03-31 01:37:06 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |