Compare commits
2 Commits
c7acb71355
...
75184d9a6e
| Author | SHA1 | Date | |
|---|---|---|---|
| 75184d9a6e | |||
| 486b423343 |
@ -42,7 +42,9 @@ namespace Hazel
|
||||
m_CheckerBoardTexture = Texture2D::Create("assets/textures/Checkerboard.png");
|
||||
|
||||
m_IconPlay = Texture2D::Create("Resources/Icons/PlayButton.png");
|
||||
m_IconStop = Texture2D::Create("Resources/Icons/PauseButton.png");
|
||||
m_IconPause = Texture2D::Create("Resources/Icons/PauseButton.png");
|
||||
m_IconStep = Texture2D::Create("Resources/Icons/StepButton.png");
|
||||
m_IconStop = Texture2D::Create("Resources/Icons/StopButton.png");
|
||||
m_IconSimulate = Texture2D::Create("Resources/Icons/SimulateButton.png");
|
||||
|
||||
m_EditorScene = CreateRef<Scene>();
|
||||
@ -76,12 +78,13 @@ namespace Hazel
|
||||
// reset Renderer Draw Stats
|
||||
Renderer2D::ResetStats();
|
||||
|
||||
m_ActiveScene->OnViewportResize((uint32_t)m_ViewPortSize.x, (uint32_t)m_ViewPortSize.y);
|
||||
|
||||
if (const auto& spec = m_FrameBuffer->GetSpecification();
|
||||
spec.Width != m_ViewPortSize.x || spec.Height != m_ViewPortSize.y)
|
||||
{
|
||||
m_FrameBuffer->Resize((uint32_t)m_ViewPortSize.x, (uint32_t)m_ViewPortSize.y);
|
||||
m_CameraController.OnResize(m_ViewPortSize.x, m_ViewPortSize.y);
|
||||
|
||||
m_EditorCamera.SetViewPortSize(m_ViewPortSize.x, m_ViewPortSize.y);
|
||||
}
|
||||
|
||||
@ -317,7 +320,7 @@ namespace Hazel
|
||||
|
||||
static float fpsRefreshTime = 0.0f;
|
||||
static float displayedFPS = 0;
|
||||
float currentTime = ImGui::GetTime();
|
||||
float currentTime = static_cast<float>(ImGui::GetTime());
|
||||
|
||||
// 每秒更新一次要显示的FPS
|
||||
if (currentTime - fpsRefreshTime >= 1.0f)
|
||||
@ -594,6 +597,10 @@ namespace Hazel
|
||||
m_SceneHierachyPanel.SetContext(m_ActiveScene);
|
||||
}
|
||||
|
||||
void EditorLayer::OnScenePause()
|
||||
{
|
||||
}
|
||||
|
||||
void EditorLayer::OnSceneSimulation()
|
||||
{
|
||||
if (m_SceneState == SceneState::Simulate)
|
||||
@ -684,6 +691,12 @@ namespace Hazel
|
||||
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x * 0.5f - size * 0.5f);
|
||||
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x * 0.5f - (size * 0.5f));
|
||||
|
||||
bool hasPlayButton = m_SceneState == SceneState::Play || m_SceneState == SceneState::Edit;
|
||||
bool hasSimulateButton = m_SceneState == SceneState::Simulate || m_SceneState == SceneState::Edit;
|
||||
bool hasPauseButton = m_SceneState != SceneState::Edit;
|
||||
|
||||
if (hasPlayButton)
|
||||
{
|
||||
Ref<Texture2D> icon = (m_SceneState == SceneState::Edit || m_SceneState == SceneState::Simulate)? m_IconPlay : m_IconStop;
|
||||
if (ImGui::ImageButton("toolbar-play-edit", icon->GetRendererID(), ImVec2{size, size}, ImVec2{0, 0}, ImVec2{1, 1}))
|
||||
{
|
||||
@ -692,9 +705,13 @@ namespace Hazel
|
||||
else if (m_SceneState == SceneState::Play)
|
||||
OnSceneStop();
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
if (hasSimulateButton)
|
||||
{
|
||||
if (hasPlayButton)
|
||||
ImGui::SameLine();
|
||||
|
||||
Ref<Texture2D> icon = (m_SceneState == SceneState::Edit || m_SceneState == SceneState::Play)? m_IconSimulate : m_IconStop;
|
||||
if (ImGui::ImageButton("toolbar-simulate", icon->GetRendererID(), ImVec2{size, size}, ImVec2{0, 0}, ImVec2{1, 1}))
|
||||
{
|
||||
@ -705,6 +722,32 @@ namespace Hazel
|
||||
}
|
||||
}
|
||||
|
||||
if (hasPauseButton)
|
||||
{
|
||||
bool isPaused = m_ActiveScene->IsPaused();
|
||||
ImGui::SameLine();
|
||||
{
|
||||
Ref<Texture2D> icon = m_IconPause;
|
||||
if (ImGui::ImageButton("toolbar-pause", icon->GetRendererID(), ImVec2{size, size}, ImVec2{0, 0}, ImVec2{1, 1}))
|
||||
{
|
||||
m_ActiveScene->SetPaused(!isPaused);
|
||||
}
|
||||
}
|
||||
|
||||
if (isPaused)
|
||||
{
|
||||
ImGui::SameLine();
|
||||
{
|
||||
Ref<Texture2D> icon = m_IconStep;
|
||||
if (ImGui::ImageButton("toolbar-step", icon->GetRendererID(), ImVec2{size, size}, ImVec2{0, 0}, ImVec2{1, 1}))
|
||||
{
|
||||
m_ActiveScene->Step();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar(2);
|
||||
ImGui::PopStyleColor(3);
|
||||
ImGui::End();
|
||||
|
||||
@ -29,6 +29,7 @@ namespace Hazel
|
||||
void OnScenePlay();
|
||||
void OnSceneSimulation();
|
||||
void OnSceneStop();
|
||||
void OnScenePause();
|
||||
|
||||
|
||||
void SaveSceneAs() const;
|
||||
@ -84,7 +85,7 @@ namespace Hazel
|
||||
|
||||
SceneState m_SceneState = SceneState::Edit;
|
||||
|
||||
Ref<Texture2D> m_IconPlay, m_IconStop, m_IconSimulate;
|
||||
Ref<Texture2D> m_IconPlay, m_IconPause, m_IconStep, m_IconStop, m_IconSimulate;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -143,6 +143,11 @@ namespace Hazel
|
||||
}
|
||||
|
||||
|
||||
void Scene::Step(const int frames)
|
||||
{
|
||||
m_StepFrame = frames;
|
||||
}
|
||||
|
||||
void Scene::OnPhysics2DStart()
|
||||
{
|
||||
b2WorldDef worldDef = b2DefaultWorldDef();
|
||||
@ -284,6 +289,8 @@ namespace Hazel
|
||||
}
|
||||
|
||||
void Scene::OnUpdateRuntime(TimeStep& ts)
|
||||
{
|
||||
if (!m_IsPaused || m_StepFrame-- > 0)
|
||||
{
|
||||
// Update scripts
|
||||
{
|
||||
@ -330,6 +337,7 @@ namespace Hazel
|
||||
transform.Rotation.z = angle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Renderer 2D
|
||||
Camera* mainCamera = nullptr;
|
||||
@ -379,6 +387,8 @@ namespace Hazel
|
||||
}
|
||||
|
||||
void Scene::OnUpdateSimulation(TimeStep& ts, const EditorCamera& camera)
|
||||
{
|
||||
if (!m_IsPaused || m_StepFrame-- > 0)
|
||||
{
|
||||
// Physics
|
||||
{
|
||||
@ -400,6 +410,7 @@ namespace Hazel
|
||||
transform.Rotation.z = angle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Render
|
||||
RenderScene(camera);
|
||||
|
||||
@ -49,6 +49,10 @@ namespace Hazel
|
||||
Entity GetEntityByUUID(UUID uuid);
|
||||
|
||||
bool IsRunning() const {return m_IsRunning; }
|
||||
bool IsPaused() const {return m_IsPaused; }
|
||||
|
||||
void SetPaused(const bool pause) {m_IsPaused = pause; }
|
||||
void Step(int frames = 1);
|
||||
|
||||
template<typename... Components>
|
||||
auto GetAllEntitiesWith()
|
||||
@ -73,6 +77,8 @@ namespace Hazel
|
||||
b2WorldId* m_PhysicsWorld = nullptr;
|
||||
|
||||
bool m_IsRunning = false;
|
||||
bool m_IsPaused = false;
|
||||
int m_StepFrame = 0;
|
||||
|
||||
std::unordered_map<UUID, entt::entity> m_EnttMap;
|
||||
|
||||
|
||||
@ -13,6 +13,8 @@
|
||||
#include "mono/jit/jit.h"
|
||||
#include "mono/metadata/assembly.h"
|
||||
#include "mono/metadata/attrdefs.h"
|
||||
#include "mono/metadata/mono-debug.h"
|
||||
#include "mono/metadata/threads.h"
|
||||
|
||||
namespace Hazel
|
||||
{
|
||||
@ -72,7 +74,7 @@ namespace Hazel
|
||||
return buffer;
|
||||
}
|
||||
|
||||
MonoAssembly* LoadMonoAssembly(const std::filesystem::path& assemblyPath)
|
||||
MonoAssembly* LoadMonoAssembly(const std::filesystem::path& assemblyPath, bool loadPDB = false)
|
||||
{
|
||||
HZ_CORE_DEBUG("Load Assemble: {0}", assemblyPath.string().c_str());
|
||||
uint32_t fileSize = 0;
|
||||
@ -88,6 +90,24 @@ namespace Hazel
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (loadPDB)
|
||||
{
|
||||
HZ_CORE_INFO("loading pdb file...");
|
||||
std::filesystem::path pdbPath(assemblyPath);
|
||||
pdbPath.replace_extension(".pdb");
|
||||
|
||||
if (std::filesystem::exists(pdbPath))
|
||||
{
|
||||
uint32_t pdbFileSize = 0;
|
||||
char* pdbFileData = ReadBytes(pdbPath, &pdbFileSize);
|
||||
mono_debug_open_image_from_memory(image, (const mono_byte*)pdbFileData, fileSize);
|
||||
HZ_CORE_INFO("loaded pdb file: {0}", pdbPath.string());
|
||||
HZ_CORE_INFO(" size: {0}", pdbFileSize);
|
||||
|
||||
delete[] pdbFileData;
|
||||
}
|
||||
}
|
||||
|
||||
std::string string = assemblyPath.string();
|
||||
MonoAssembly* assembly = mono_assembly_load_from_full(image, string.c_str(), &status, 0);
|
||||
mono_image_close(image);
|
||||
@ -152,6 +172,8 @@ namespace Hazel
|
||||
Scope<filewatch::FileWatch<std::string>> AppAssemblyFileWatcher;
|
||||
bool AssemblyReloading = false;
|
||||
|
||||
bool EnableDebugging = false;
|
||||
|
||||
// runtime
|
||||
Scene* SceneContext = nullptr;
|
||||
};
|
||||
@ -235,7 +257,7 @@ namespace Hazel
|
||||
|
||||
// TODO: move this later
|
||||
s_Data->CoreAssemblyFilePath = assemblePath;
|
||||
s_Data->CoreAssembly = Utils::LoadMonoAssembly(assemblePath);
|
||||
s_Data->CoreAssembly = Utils::LoadMonoAssembly(assemblePath, s_Data->EnableDebugging);
|
||||
s_Data->CoreAssemblyImage = mono_assembly_get_image(s_Data->CoreAssembly);
|
||||
|
||||
// Utils::PrintAssemblyTypes(s_Data->CoreAssembly);
|
||||
@ -245,7 +267,7 @@ namespace Hazel
|
||||
{
|
||||
// TODO: move this later
|
||||
s_Data->AppAssemblyFilePath = assemblePath;
|
||||
s_Data->AppAssembly = Utils::LoadMonoAssembly(assemblePath);
|
||||
s_Data->AppAssembly = Utils::LoadMonoAssembly(assemblePath, s_Data->EnableDebugging);
|
||||
s_Data->AppAssemblyImage = mono_assembly_get_image(s_Data->AppAssembly);
|
||||
|
||||
s_Data->AppAssemblyFileWatcher = CreateScope<filewatch::FileWatch<std::string>>(assemblePath.string(), OnAssemblyFileSystemEvent);
|
||||
@ -408,6 +430,18 @@ namespace Hazel
|
||||
mono_set_dirs("Resources", "Resources");
|
||||
mono_set_assemblies_path("Resources/mono");
|
||||
|
||||
if (s_Data->EnableDebugging)
|
||||
{
|
||||
const char* argv[2]
|
||||
{
|
||||
"--debugger-agent=transport=dt_socket,address=127.0.0.1:2550,server=y,suspend=n,loglevel=3,logfile=MonoDebugger.log",
|
||||
"--soft-breakpoints"
|
||||
};
|
||||
|
||||
mono_jit_parse_options(2, (char**)argv);
|
||||
mono_debug_init(MONO_DEBUG_FORMAT_MONO);
|
||||
}
|
||||
|
||||
MonoDomain* rootDomain = mono_jit_init("HazelJITRuntime");
|
||||
|
||||
const char* monoPath = mono_assembly_getrootdir();
|
||||
@ -419,6 +453,11 @@ namespace Hazel
|
||||
}
|
||||
// Storage the root Domain ptr
|
||||
s_Data->RootDomain = rootDomain;
|
||||
|
||||
if (s_Data->EnableDebugging)
|
||||
mono_debug_domain_create(s_Data->RootDomain);
|
||||
|
||||
mono_thread_set_main(mono_thread_current());
|
||||
}
|
||||
|
||||
void ScriptEngine::MonoShutdown()
|
||||
@ -468,7 +507,8 @@ namespace Hazel
|
||||
|
||||
MonoObject* ScriptClass::InvokeMethod(MonoObject* instance, MonoMethod* method, void** param)
|
||||
{
|
||||
return mono_runtime_invoke(method, instance, param, nullptr);
|
||||
MonoObject* expection = nullptr;
|
||||
return mono_runtime_invoke(method, instance, param, &expection);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user