feat: add --direct-enter option to skip to world scene

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.
This commit is contained in:
2026-08-05 15:30:14 +08:00
parent 30b4060fb5
commit 277aab1b81
4 changed files with 38 additions and 15 deletions

View File

@@ -13,5 +13,6 @@ struct Argument {
std::optional<int> log_level;
std::optional<bool> enable_filelog;
std::optional<bool> enable_consolelog;
std::optional<bool> direct_enter;
};
} // namespace Cubed

View File

@@ -36,6 +36,7 @@ public:
App& app();
WorldSceneParam& world_scene_param();
void push(SceneType type);
private:
enum class OperationType { PUSH, POP, CHANGE };
@@ -51,7 +52,7 @@ private:
std::stack<std::unique_ptr<Scene>> m_scenes;
void process_operation();
void change(SceneType type);
void push(SceneType type);
void pop(bool re_enter = true);
std::unique_ptr<Scene> create_scene(SceneType);

View File

@@ -90,7 +90,14 @@ void App::init(int argc, char** argv) {
m_texture_manager.init_texture();
Logger::info("Texture Load Success");
m_scene_manager.request_push(SceneType::MAIN_MENU);
m_scene_manager.push(SceneType::MAIN_MENU);
if (m_argument.direct_enter) {
if (m_argument.port) {
m_scene_manager.request_push(SceneType::WORLD);
} else {
throw std::runtime_error("You need use -p to specify a port");
}
}
last_tick = SDL_GetTicks();
current_tick = SDL_GetTicks();
{
@@ -181,7 +188,9 @@ void App::handle_argument(int argc, char** argv) {
{"--enable-filelog",
[&](ArgParser&) { m_argument.enable_filelog = true; }},
{"--enale-consolelog",
[&](ArgParser&) { m_argument.enable_consolelog = true; }}
[&](ArgParser&) { m_argument.enable_consolelog = true; }},
{"--direct-enter",
[&](ArgParser&) { m_argument.direct_enter = true; }}
};
ArgParser parser(argc, argv);

View File

@@ -126,9 +126,20 @@ bool WorldScene::handle_event(const Event& e) {
e);
}
void WorldScene::on_enter() {
auto& param = m_scene_manager.world_scene_param();
load_config();
m_error_ui.init();
m_client = std::make_shared<NetworkClient>(m_client_world);
if (m_argument.direct_enter) {
if (!m_argument.ip) {
ChunkGenerator::init();
m_server.start_server(*m_argument.port);
m_client->start("127.0.0.1", *m_argument.port);
} else {
m_client->start(*m_argument.ip, *m_argument.port);
}
} else {
auto& param = m_scene_manager.world_scene_param();
if (param.host_game) {
if (param.seed) {
@@ -139,9 +150,10 @@ void WorldScene::on_enter() {
}
m_server.start_server(param.port);
}
m_client = std::make_shared<NetworkClient>(m_client_world);
m_client->start(param.ip, param.port);
}
// init will send packet
try {