mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
Support a new CLI flag that launches the app directly into the world scene. If no IP is provided, it starts a local server on the specified port and connects to 127.0.0.1; otherwise it connects to the given IP. With this flag enabled, a port must be specified via -p. Also expose SceneManager::push as public so scenes can be pushed immediately when bypassing the normal menu flow.
60 lines
1.4 KiB
C++
60 lines
1.4 KiB
C++
#pragma once
|
|
#include "Cubed/scene/scene.hpp"
|
|
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <stack>
|
|
#include <vector>
|
|
|
|
namespace Cubed {
|
|
class App;
|
|
|
|
struct WorldSceneParam {
|
|
bool host_game = true;
|
|
std::optional<unsigned> seed = std::nullopt;
|
|
std::string ip{"127.0.0.1"};
|
|
int port = 25530;
|
|
};
|
|
|
|
class SceneManager {
|
|
public:
|
|
SceneManager(const SceneManager&) = delete;
|
|
SceneManager(SceneManager&&) = delete;
|
|
SceneManager& operator=(const SceneManager&) = delete;
|
|
SceneManager& operator=(SceneManager&&) = delete;
|
|
SceneManager(App& app);
|
|
~SceneManager();
|
|
|
|
void update(float dt);
|
|
void render(Renderer& renderer);
|
|
|
|
bool handle_event(const Event& e);
|
|
|
|
void request_change(SceneType type);
|
|
void request_push(SceneType type);
|
|
void request_pop();
|
|
|
|
App& app();
|
|
WorldSceneParam& world_scene_param();
|
|
void push(SceneType type);
|
|
|
|
private:
|
|
enum class OperationType { PUSH, POP, CHANGE };
|
|
struct SceneOperation {
|
|
OperationType type;
|
|
std::optional<SceneType> scene;
|
|
};
|
|
|
|
App& m_app;
|
|
WorldSceneParam m_world_param;
|
|
std::vector<std::unique_ptr<Scene>> m_pending_delete_scene;
|
|
std::optional<SceneOperation> m_operation;
|
|
std::stack<std::unique_ptr<Scene>> m_scenes;
|
|
void process_operation();
|
|
void change(SceneType type);
|
|
|
|
void pop(bool re_enter = true);
|
|
|
|
std::unique_ptr<Scene> create_scene(SceneType);
|
|
};
|
|
} // namespace Cubed
|