diff --git a/include/app/application.h b/include/app/application.h index 56c953e..61f3ee2 100644 --- a/include/app/application.h +++ b/include/app/application.h @@ -9,10 +9,7 @@ namespace extra2d { // 前向声明 class Input; -class AudioEngine; class TimerManager; -class EventQueue; -class EventDispatcher; // ============================================================================ // Application 配置 @@ -56,10 +53,7 @@ public: Window &window() { return *window_; } Input &input(); - AudioEngine &audio(); TimerManager &timers(); - EventQueue &eventQueue(); - EventDispatcher &eventDispatcher(); float deltaTime() const { return deltaTime_; } float totalTime() const { return totalTime_; } @@ -78,8 +72,6 @@ private: UniquePtr window_; UniquePtr timerManager_; - UniquePtr eventQueue_; - UniquePtr eventDispatcher_; bool initialized_ = false; bool running_ = false; diff --git a/include/audio/audio_engine.h b/include/audio/audio_engine.h deleted file mode 100644 index 2230c73..0000000 --- a/include/audio/audio_engine.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace extra2d { - -class Sound; - -class AudioEngine { -public: - static AudioEngine &getInstance(); - - AudioEngine(const AudioEngine &) = delete; - AudioEngine &operator=(const AudioEngine &) = delete; - AudioEngine(AudioEngine &&) = delete; - AudioEngine &operator=(AudioEngine &&) = delete; - - bool initialize(); - void shutdown(); - - IntrusivePtr loadSound(const std::string &filePath); - IntrusivePtr loadSound(const std::string &name, - const std::string &filePath); - - IntrusivePtr getSound(const std::string &name); - void unloadSound(const std::string &name); - void unloadAllSounds(); - - void setMasterVolume(float volume); - float getMasterVolume() const; - - void pauseAll(); - void resumeAll(); - void stopAll(); - -private: - AudioEngine() = default; - ~AudioEngine(); - - std::unordered_map> sounds_; - float masterVolume_ = 1.0f; - bool initialized_ = false; -}; - -} // namespace extra2d diff --git a/include/audio/sound.h b/include/audio/sound.h deleted file mode 100644 index a095052..0000000 --- a/include/audio/sound.h +++ /dev/null @@ -1,57 +0,0 @@ -#pragma once - -#include -#include - -struct Mix_Chunk; - -namespace extra2d { - -class AudioEngine; - -class Sound : public RefCounted { -public: - ~Sound(); - - Sound(const Sound&) = delete; - Sound& operator=(const Sound&) = delete; - - bool play(); - void pause(); - void resume(); - void stop(); - - bool isPlaying() const; - bool isPaused() const; - - void setVolume(float volume); - float getVolume() const { return volume_; } - - void setLooping(bool looping); - bool isLooping() const { return looping_; } - - void setPitch(float pitch); - float getPitch() const { return pitch_; } - - float getDuration() const; - float getCursor() const; - void setCursor(float seconds); - - const std::string& getFilePath() const { return filePath_; } - const std::string& name() const { return name_; } - -private: - friend class AudioEngine; - - Sound(const std::string& name, const std::string& filePath, Mix_Chunk* chunk); - - std::string name_; - std::string filePath_; - Mix_Chunk* chunk_ = nullptr; - int channel_ = -1; // SDL_mixer 分配的通道,-1 表示未播放 - float volume_ = 1.0f; - float pitch_ = 1.0f; - bool looping_ = false; -}; - -} // namespace extra2d diff --git a/include/event/event.h b/include/event/event.h deleted file mode 100644 index 8ef2623..0000000 --- a/include/event/event.h +++ /dev/null @@ -1,172 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -namespace extra2d { - -// ============================================================================ -// 事件类型枚举 -// ============================================================================ -enum class EventType { - None = 0, - - // 窗口事件 - WindowClose, - WindowResize, - WindowFocus, - WindowLostFocus, - WindowMoved, - - // 键盘事件 - KeyPressed, - KeyReleased, - KeyRepeat, - - // 鼠标事件 - MouseButtonPressed, - MouseButtonReleased, - MouseMoved, - MouseScrolled, - - // UI 事件 - UIHoverEnter, - UIHoverExit, - UIPressed, - UIReleased, - UIClicked, - - // 游戏手柄事件 - GamepadConnected, - GamepadDisconnected, - GamepadButtonPressed, - GamepadButtonReleased, - GamepadAxisMoved, - - // 触摸事件 (移动端) - TouchBegan, - TouchMoved, - TouchEnded, - TouchCancelled, - - // 自定义事件 - Custom -}; - -// ============================================================================ -// 键盘事件数据 -// ============================================================================ -struct KeyEvent { - int keyCode; - int scancode; - int mods; // 修饰键 (Shift, Ctrl, Alt, etc.) -}; - -// ============================================================================ -// 鼠标事件数据 -// ============================================================================ -struct MouseButtonEvent { - int button; - int mods; - Vec2 position; -}; - -struct MouseMoveEvent { - Vec2 position; - Vec2 delta; -}; - -struct MouseScrollEvent { - Vec2 offset; - Vec2 position; -}; - -// ============================================================================ -// 窗口事件数据 -// ============================================================================ -struct WindowResizeEvent { - int width; - int height; -}; - -struct WindowMoveEvent { - int x; - int y; -}; - -// ============================================================================ -// 游戏手柄事件数据 -// ============================================================================ -struct GamepadButtonEvent { - int gamepadId; - int button; -}; - -struct GamepadAxisEvent { - int gamepadId; - int axis; - float value; -}; - -// ============================================================================ -// 触摸事件数据 -// ============================================================================ -struct TouchEvent { - int touchId; - Vec2 position; -}; - -// ============================================================================ -// 自定义事件数据 -// ============================================================================ -struct CustomEvent { - uint32_t id; - void *data; -}; - -// ============================================================================ -// 事件结构 -// ============================================================================ -struct Event { - EventType type = EventType::None; - double timestamp = 0.0; - bool handled = false; - - // 事件数据联合体 - std::variant - data; - - // 便捷访问方法 - bool isWindowEvent() const { - return type == EventType::WindowClose || type == EventType::WindowResize || - type == EventType::WindowFocus || - type == EventType::WindowLostFocus || type == EventType::WindowMoved; - } - - bool isKeyboardEvent() const { - return type == EventType::KeyPressed || type == EventType::KeyReleased || - type == EventType::KeyRepeat; - } - - bool isMouseEvent() const { - return type == EventType::MouseButtonPressed || - type == EventType::MouseButtonReleased || - type == EventType::MouseMoved || type == EventType::MouseScrolled; - } - - // 静态工厂方法 - static Event createWindowResize(int width, int height); - static Event createWindowClose(); - static Event createKeyPress(int keyCode, int scancode, int mods); - static Event createKeyRelease(int keyCode, int scancode, int mods); - static Event createMouseButtonPress(int button, int mods, const Vec2 &pos); - static Event createMouseButtonRelease(int button, int mods, const Vec2 &pos); - static Event createMouseMove(const Vec2 &pos, const Vec2 &delta); - static Event createMouseScroll(const Vec2 &offset, const Vec2 &pos); -}; - -} // namespace extra2d diff --git a/include/event/event_dispatcher.h b/include/event/event_dispatcher.h deleted file mode 100644 index e3c1a2d..0000000 --- a/include/event/event_dispatcher.h +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -namespace extra2d { - -// ============================================================================ -// 事件监听器 ID -// ============================================================================ -using ListenerId = uint64_t; - -// ============================================================================ -// 事件分发器 -// ============================================================================ -class EventDispatcher { -public: - using EventCallback = std::function; - - EventDispatcher(); - ~EventDispatcher() = default; - - // 添加监听器 - ListenerId addListener(EventType type, EventCallback callback); - - // 移除监听器 - void removeListener(ListenerId id); - void removeAllListeners(EventType type); - void removeAllListeners(); - - // 分发事件 - void dispatch(Event &event); - void dispatch(const Event &event); - - // 处理事件队列 - void processQueue(class EventQueue &queue); - - // 统计 - size_t getListenerCount(EventType type) const; - size_t getTotalListenerCount() const; - -private: - struct Listener { - ListenerId id; - EventType type; - EventCallback callback; - }; - - std::unordered_map> listeners_; - ListenerId nextId_; -}; - -} // namespace extra2d diff --git a/include/event/event_queue.h b/include/event/event_queue.h deleted file mode 100644 index 8137dd4..0000000 --- a/include/event/event_queue.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -namespace extra2d { - -// ============================================================================ -// 事件队列 - 线程安全的事件队列 -// ============================================================================ -class EventQueue { -public: - EventQueue(); - ~EventQueue() = default; - - // 添加事件到队列 - void push(const Event &event); - void push(Event &&event); - - // 从队列取出事件 - bool poll(Event &event); - - // 查看队列头部事件(不移除) - bool peek(Event &event) const; - - // 清空队列 - void clear(); - - // 队列状态 - bool empty() const; - size_t size() const; - -private: - std::queue queue_; - mutable std::mutex mutex_; -}; - -} // namespace extra2d diff --git a/include/extra2d.h b/include/extra2d.h index cce5229..49b6d34 100644 --- a/include/extra2d.h +++ b/include/extra2d.h @@ -16,18 +16,7 @@ #include #include -// Event -#include -#include -#include -#include - -// Audio -#include