feat: add more collider types + camera snapping fix
This commit is contained in:
@@ -136,6 +136,7 @@ private:
|
||||
bool m_SaveAsDialog{false};
|
||||
bool m_ItemWasActive{false};
|
||||
bool m_EditPending{false};
|
||||
bool m_CameraHadInput{false};
|
||||
};
|
||||
|
||||
#endif // EDITOR_EDITOR_H
|
||||
|
||||
@@ -11,6 +11,17 @@
|
||||
|
||||
class Scene;
|
||||
|
||||
struct EditGestureState {
|
||||
bool itemWasActive{false};
|
||||
bool itemActive{false};
|
||||
bool mouseReleased{false};
|
||||
bool keyReleased{false};
|
||||
bool keyboardDrivesCamera{false};
|
||||
bool editPending{false};
|
||||
};
|
||||
|
||||
[[nodiscard]] bool EndsEditGesture(const EditGestureState& state);
|
||||
|
||||
class UndoStack final {
|
||||
public:
|
||||
static constexpr std::size_t MaxSteps = 64;
|
||||
|
||||
+11
-4
@@ -101,8 +101,9 @@ void Editor::onImGuiBegin(float dt)
|
||||
ApplyPick();
|
||||
HandleShortcuts();
|
||||
|
||||
m_CameraHadInput = UsesEditorCamera() && (m_Viewport.hovered || m_Viewport.focused || m_Camera.IsLooking());
|
||||
if (UsesEditorCamera()) {
|
||||
m_Camera.Update(dt, m_Viewport.hovered || m_Viewport.focused || m_Camera.IsLooking());
|
||||
m_Camera.Update(dt, m_CameraHadInput);
|
||||
}
|
||||
|
||||
if (m_ShaderHotReload.Poll(dt)) {
|
||||
@@ -153,10 +154,16 @@ void Editor::onEndFrame()
|
||||
}
|
||||
|
||||
const bool itemActive = ImGui::IsAnyItemActive() || ImGuizmo::IsUsing();
|
||||
const bool gestureEnded = (m_ItemWasActive && !itemActive) || ImGui::IsMouseReleased(ImGuiMouseButton_Left) ||
|
||||
AnyKeyReleased() || std::exchange(m_EditPending, false);
|
||||
const bool gestureEnded = EndsEditGesture({
|
||||
.itemWasActive = m_ItemWasActive,
|
||||
.itemActive = itemActive,
|
||||
.mouseReleased = ImGui::IsMouseReleased(ImGuiMouseButton_Left),
|
||||
.keyReleased = AnyKeyReleased(),
|
||||
.keyboardDrivesCamera = m_CameraHadInput,
|
||||
.editPending = std::exchange(m_EditPending, false),
|
||||
});
|
||||
m_ItemWasActive = itemActive;
|
||||
if (gestureEnded && !itemActive && m_PlayMode.IsEditing()) {
|
||||
if (gestureEnded && m_PlayMode.IsEditing()) {
|
||||
RecordEdits();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,16 @@
|
||||
#include <destrum/Scene/Scene.h>
|
||||
#include <destrum/Serialization/SceneSerializer.h>
|
||||
|
||||
bool EndsEditGesture(const EditGestureState& state)
|
||||
{
|
||||
if (state.itemActive) {
|
||||
return false;
|
||||
}
|
||||
// Capturing a snapshot serializes the whole scene, doing that on every WASD release while flying hitches the camera
|
||||
const bool keyGesture = state.keyReleased && !state.keyboardDrivesCamera;
|
||||
return state.itemWasActive || state.mouseReleased || keyGesture || state.editPending;
|
||||
}
|
||||
|
||||
std::optional<UndoStack::Snapshot> UndoStack::Capture(Scene& scene)
|
||||
{
|
||||
const auto root = SceneSerializer::Capture(scene);
|
||||
|
||||
Reference in New Issue
Block a user