refactor(editor): reorganize includes and enhance EditorManager initialization

- Moved the declaration of `AgentControlServer` to a forward declaration in the header file for better clarity and organization.
- Updated the `EditorManager` constructor to initialize the version string and popup manager context.
- Added conditional compilation for gRPC-related includes and commented out the agent control server initialization for future reference.
- Ensured consistent definition of `IMGUI_DEFINE_MATH_OPERATORS` across multiple files to prevent potential issues with ImGui usage.

Benefits:
- Improved code organization and readability.
- Enhanced maintainability by clarifying the initialization process and managing includes effectively.
This commit is contained in:
scawful
2025-10-11 14:37:34 -04:00
parent 5ba66b7898
commit ab73a09f47
12 changed files with 80 additions and 18 deletions

View File

@@ -3,6 +3,11 @@
#if defined(YAZE_WITH_GRPC)
// Must define before any ImGui includes (test_manager.h includes ImGui headers)
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
#include <string>
#include "absl/synchronization/mutex.h"

View File

@@ -47,25 +47,29 @@
#ifdef YAZE_ENABLE_GTEST
#include "app/test/unit_test_suite.h"
#endif
#ifdef YAZE_WITH_GRPC
#include "app/test/z3ed_test_suite.h"
#endif
#include "app/editor/system/settings_editor.h"
#include "app/editor/system/toast_manager.h"
#include "app/emu/emulator.h"
#include "app/gfx/performance/performance_dashboard.h"
#include "app/editor/editor.h"
#ifdef YAZE_WITH_GRPC
#include "app/core/service/screenshot_utils.h"
#include "app/editor/agent/agent_chat_widget.h"
#include "cli/service/agent/agent_control_server.h"
#include "cli/service/agent/conversational_agent_service.h"
#include "cli/service/ai/gemini_ai_service.h"
#include "app/test/z3ed_test_suite.h"
#include "absl/flags/flag.h"
#endif
#ifdef YAZE_WITH_GRPC
// Declare the agent_control flag (defined in src/cli/flags.cc)
// ABSL_DECLARE_FLAG(bool, agent_control);
#include "app/editor/agent/automation_bridge.h"
#endif
#include "imgui/imgui.h"
#include "imgui/misc/cpp/imgui_stdlib.h"
#include "util/log.h"
@@ -86,7 +90,15 @@ std::string GetEditorName(EditorType type) {
} // namespace
EditorManager::EditorManager() : blank_editor_set_(nullptr, &user_settings_) {
std::stringstream ss;
ss << YAZE_VERSION_MAJOR << "." << YAZE_VERSION_MINOR << "."
<< YAZE_VERSION_PATCH;
ss >> version_;
context_.popup_manager = popup_manager_.get();
}
EditorManager::~EditorManager() = default;
void EditorManager::InitializeTestSuites() {
auto& test_manager = test::TestManager::Get();
@@ -543,10 +555,10 @@ void EditorManager::Initialize(gfx::IRenderer* renderer, const std::string& file
[this]() { proposal_drawer_.Toggle(); });
// Start the agent control server if the flag is set
if (absl::GetFlag(FLAGS_agent_control)) {
agent_control_server_ = std::make_unique<agent::AgentControlServer>(&emulator_);
agent_control_server_->Start();
}
// if (absl::GetFlag(FLAGS_agent_control)) {
// agent_control_server_ = std::make_unique<agent::AgentControlServer>(&emulator_);
// agent_control_server_->Start();
// }
#endif
// Testing shortcuts (only when tests are enabled)

View File

@@ -1,9 +1,10 @@
#ifndef YAZE_APP_EDITOR_EDITOR_MANAGER_H
#define YAZE_APP_EDITOR_EDITOR_MANAGER_H
#define IMGUI_DEFINE_MATH_OPERATORS
#include "app/editor/system/user_settings.h"
#include "app/editor/ui/workspace_manager.h"
#define IMGUI_DEFINE_MATH_OPERATORS
#include "imgui/imgui.h"
@@ -42,6 +43,10 @@
#include "yaze_config.h"
#ifdef YAZE_WITH_GRPC
// Forward declarations for gRPC-dependent types
namespace yaze::agent {
class AgentControlServer;
}
#endif
namespace yaze {
@@ -103,13 +108,9 @@ class EditorSet {
*/
class EditorManager {
public:
EditorManager() : blank_editor_set_(nullptr, &user_settings_) {
std::stringstream ss;
ss << YAZE_VERSION_MAJOR << "." << YAZE_VERSION_MINOR << "."
<< YAZE_VERSION_PATCH;
ss >> version_;
context_.popup_manager = popup_manager_.get();
}
// Constructor and destructor must be defined in .cc file for std::unique_ptr with forward-declared types
EditorManager();
~EditorManager();
void Initialize(gfx::IRenderer* renderer, const std::string& filename = "");
@@ -278,7 +279,7 @@ class EditorManager {
#ifdef YAZE_WITH_GRPC
// Agent editor - manages chat, collaboration, and network coordination
AgentEditor agent_editor_;
std::unique_ptr<agent::AgentControlServer> agent_control_server_;
std::unique_ptr<yaze::agent::AgentControlServer> agent_control_server_;
#endif
std::string version_ = "";

View File

@@ -6,6 +6,11 @@
#include <string>
#include <unordered_map>
// Must define before including imgui.h
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
#include "imgui/imgui.h"
namespace yaze {

View File

@@ -5,6 +5,11 @@
#include <string>
#include <unordered_map>
// Must define before including imgui.h
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
#include "imgui/imgui.h"
namespace yaze {

View File

@@ -4,6 +4,11 @@
#include <deque>
#include <string>
// Must define before including imgui.h
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
#include "imgui/imgui.h"
namespace yaze {

View File

@@ -5,6 +5,11 @@
#include <string>
#include <vector>
// Must define before including imgui.h
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
#include "app/gui/icons.h"
#include "imgui/imgui.h"

View File

@@ -1,4 +1,10 @@
// AppDelegate.mm
// Must define before any ImGui includes (needed by imgui_test_engine via editor_manager.h)
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
#import "app/platform/app_delegate.h"
#import "app/core/controller.h"
#import "util/file_util.h"

View File

@@ -1,3 +1,8 @@
// Must define before any ImGui includes
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
#include <gtest/gtest.h>
#include <filesystem>
#include <fstream>

View File

@@ -2,6 +2,10 @@
// Updated for DungeonEditorV2 architecture - uses ObjectDrawer (production system)
// instead of the obsolete ObjectRenderer
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
#include "app/zelda3/dungeon/object_drawer.h"
#include "app/zelda3/dungeon/room.h"
#include "app/zelda3/dungeon/room_object.h"

View File

@@ -1,6 +1,10 @@
#ifndef YAZE_TEST_TEST_UTILS_H
#define YAZE_TEST_TEST_UTILS_H
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
#include <string>
#include <vector>
#include <filesystem>

View File

@@ -1,5 +1,10 @@
#define SDL_MAIN_HANDLED
// Must define before any ImGui includes
#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif
#include <gtest/gtest.h>
#include <SDL.h>
#include <iostream>