refactor(editor): improve session management in EditorManager
- Refactored session management methods in EditorManager to enhance clarity and maintainability. - Adjusted context handling for session switching and duplication, ensuring proper session IDs are set. - Updated the editor dependencies to use IRenderer instead of Renderer, aligning with the new graphics interface. Benefits: - Streamlines session management logic, leading to a more organized codebase. - Improves compatibility with future graphics enhancements by adopting the IRenderer interface.
This commit is contained in:
@@ -20,7 +20,7 @@ namespace yaze {
|
|||||||
// Forward declarations
|
// Forward declarations
|
||||||
class Rom;
|
class Rom;
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
class Renderer;
|
class IRenderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -72,10 +72,9 @@ struct EditorDependencies {
|
|||||||
ShortcutManager* shortcut_manager = nullptr;
|
ShortcutManager* shortcut_manager = nullptr;
|
||||||
UserSettings* user_settings = nullptr;
|
UserSettings* user_settings = nullptr;
|
||||||
size_t session_id = 0;
|
size_t session_id = 0;
|
||||||
|
|
||||||
// Optional dependencies for specialized editors
|
gfx::IRenderer* renderer = nullptr;
|
||||||
gfx::Renderer* renderer = nullptr; // For emulator, dungeon editor
|
void* custom_data = nullptr;
|
||||||
void* custom_data = nullptr; // Type-erased for editor-specific needs
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct EditorContext {
|
struct EditorContext {
|
||||||
|
|||||||
@@ -2232,9 +2232,9 @@ void EditorManager::CreateNewSession() {
|
|||||||
// Wire editor contexts for new session
|
// Wire editor contexts for new session
|
||||||
if (!sessions_.empty()) {
|
if (!sessions_.empty()) {
|
||||||
RomSession& session = sessions_.back();
|
RomSession& session = sessions_.back();
|
||||||
session.editors.set_user_settings(&user_settings_);
|
session.editors.set_user_settings(&user_settings_);
|
||||||
for (auto* editor : session.editors.active_editors_) {
|
for (auto* editor : session.editors.active_editors_) {
|
||||||
editor->set_context(&context_);
|
editor->set_context(&context_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2265,9 +2265,9 @@ void EditorManager::DuplicateCurrentSession() {
|
|||||||
// Wire editor contexts for duplicated session
|
// Wire editor contexts for duplicated session
|
||||||
if (!sessions_.empty()) {
|
if (!sessions_.empty()) {
|
||||||
RomSession& session = sessions_.back();
|
RomSession& session = sessions_.back();
|
||||||
for (auto* editor : session.editors.active_editors_) {
|
for (auto* editor : session.editors.active_editors_) {
|
||||||
editor->set_context(&context_);
|
editor->set_context(&context_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2282,7 +2282,10 @@ void EditorManager::CloseCurrentSession() {
|
|||||||
if (active_index < sessions_.size()) {
|
if (active_index < sessions_.size()) {
|
||||||
current_rom_ = &sessions_[active_index].rom;
|
current_rom_ = &sessions_[active_index].rom;
|
||||||
current_editor_set_ = &sessions_[active_index].editors;
|
current_editor_set_ = &sessions_[active_index].editors;
|
||||||
|
context_.session_id = active_index;
|
||||||
|
#ifdef YAZE_ENABLE_TESTING
|
||||||
test::TestManager::Get().SetCurrentRom(current_rom_);
|
test::TestManager::Get().SetCurrentRom(current_rom_);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2298,29 +2301,37 @@ void EditorManager::RemoveSession(size_t index) {
|
|||||||
if (active_index < sessions_.size()) {
|
if (active_index < sessions_.size()) {
|
||||||
current_rom_ = &sessions_[active_index].rom;
|
current_rom_ = &sessions_[active_index].rom;
|
||||||
current_editor_set_ = &sessions_[active_index].editors;
|
current_editor_set_ = &sessions_[active_index].editors;
|
||||||
|
context_.session_id = active_index;
|
||||||
|
#ifdef YAZE_ENABLE_TESTING
|
||||||
test::TestManager::Get().SetCurrentRom(current_rom_);
|
test::TestManager::Get().SetCurrentRom(current_rom_);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::SwitchToSession(size_t index) {
|
void EditorManager::SwitchToSession(size_t index) {
|
||||||
if (session_coordinator_) {
|
if (!session_coordinator_) {
|
||||||
session_coordinator_->SwitchToSession(index);
|
return;
|
||||||
|
}
|
||||||
// Update current pointers after session switch
|
|
||||||
if (index < sessions_.size()) {
|
session_coordinator_->SwitchToSession(index);
|
||||||
|
|
||||||
|
if (index >= sessions_.size()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto& session = sessions_[index];
|
auto& session = sessions_[index];
|
||||||
current_rom_ = &session.rom;
|
current_rom_ = &session.rom;
|
||||||
current_editor_set_ = &session.editors;
|
current_editor_set_ = &session.editors;
|
||||||
|
|
||||||
// Update test manager with current ROM for ROM-dependent tests
|
if (context_.session_id != index) {
|
||||||
util::logf("EditorManager: Setting ROM in TestManager - %p ('%s')",
|
context_.session_id = index;
|
||||||
(void*)current_rom_,
|
|
||||||
current_rom_ ? current_rom_->title().c_str() : "null");
|
|
||||||
test::TestManager::Get().SetCurrentRom(current_rom_);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef YAZE_ENABLE_TESTING
|
||||||
|
test::TestManager::Get().SetCurrentRom(current_rom_);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t EditorManager::GetCurrentSessionIndex() const {
|
size_t EditorManager::GetCurrentSessionIndex() const {
|
||||||
|
|||||||
Reference in New Issue
Block a user