mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
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:
@@ -13,5 +13,6 @@ struct Argument {
|
|||||||
std::optional<int> log_level;
|
std::optional<int> log_level;
|
||||||
std::optional<bool> enable_filelog;
|
std::optional<bool> enable_filelog;
|
||||||
std::optional<bool> enable_consolelog;
|
std::optional<bool> enable_consolelog;
|
||||||
|
std::optional<bool> direct_enter;
|
||||||
};
|
};
|
||||||
} // namespace Cubed
|
} // namespace Cubed
|
||||||
@@ -36,6 +36,7 @@ public:
|
|||||||
|
|
||||||
App& app();
|
App& app();
|
||||||
WorldSceneParam& world_scene_param();
|
WorldSceneParam& world_scene_param();
|
||||||
|
void push(SceneType type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum class OperationType { PUSH, POP, CHANGE };
|
enum class OperationType { PUSH, POP, CHANGE };
|
||||||
@@ -51,7 +52,7 @@ private:
|
|||||||
std::stack<std::unique_ptr<Scene>> m_scenes;
|
std::stack<std::unique_ptr<Scene>> m_scenes;
|
||||||
void process_operation();
|
void process_operation();
|
||||||
void change(SceneType type);
|
void change(SceneType type);
|
||||||
void push(SceneType type);
|
|
||||||
void pop(bool re_enter = true);
|
void pop(bool re_enter = true);
|
||||||
|
|
||||||
std::unique_ptr<Scene> create_scene(SceneType);
|
std::unique_ptr<Scene> create_scene(SceneType);
|
||||||
|
|||||||
13
src/app.cpp
13
src/app.cpp
@@ -90,7 +90,14 @@ void App::init(int argc, char** argv) {
|
|||||||
m_texture_manager.init_texture();
|
m_texture_manager.init_texture();
|
||||||
Logger::info("Texture Load Success");
|
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();
|
last_tick = SDL_GetTicks();
|
||||||
current_tick = SDL_GetTicks();
|
current_tick = SDL_GetTicks();
|
||||||
{
|
{
|
||||||
@@ -181,7 +188,9 @@ void App::handle_argument(int argc, char** argv) {
|
|||||||
{"--enable-filelog",
|
{"--enable-filelog",
|
||||||
[&](ArgParser&) { m_argument.enable_filelog = true; }},
|
[&](ArgParser&) { m_argument.enable_filelog = true; }},
|
||||||
{"--enale-consolelog",
|
{"--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);
|
ArgParser parser(argc, argv);
|
||||||
|
|||||||
@@ -126,9 +126,20 @@ bool WorldScene::handle_event(const Event& e) {
|
|||||||
e);
|
e);
|
||||||
}
|
}
|
||||||
void WorldScene::on_enter() {
|
void WorldScene::on_enter() {
|
||||||
auto& param = m_scene_manager.world_scene_param();
|
|
||||||
load_config();
|
load_config();
|
||||||
m_error_ui.init();
|
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.host_game) {
|
||||||
if (param.seed) {
|
if (param.seed) {
|
||||||
@@ -139,9 +150,10 @@ void WorldScene::on_enter() {
|
|||||||
}
|
}
|
||||||
m_server.start_server(param.port);
|
m_server.start_server(param.port);
|
||||||
}
|
}
|
||||||
m_client = std::make_shared<NetworkClient>(m_client_world);
|
|
||||||
|
|
||||||
m_client->start(param.ip, param.port);
|
m_client->start(param.ip, param.port);
|
||||||
|
}
|
||||||
|
|
||||||
// init will send packet
|
// init will send packet
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user