From 529455f437300d15453d78bd5566218f21db9421 Mon Sep 17 00:00:00 2001 From: Jeija Date: Fri, 9 Sep 2016 11:04:42 +0200 Subject: [PATCH] Enable falling through the planet Falling through the planet basically behaves like falling through a torus with a hole. There are no special visuals to it, it's basically just teleporting to the other side of the planet and reversing the vertical velocity. --- src/defaultsettings.cpp | 1 + src/game.cpp | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 79e72184..95e3a286 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -326,6 +326,7 @@ void set_default_settings(Settings *settings) settings->setDefault("planet_keep_scale", "true"); settings->setDefault("planet_centrifugal_enable", "true"); settings->setDefault("planet_realistic_gravity", "false"); + settings->setDefault("planet_fallthrough_enable", "true"); // IPv6 settings->setDefault("enable_ipv6", "true"); diff --git a/src/game.cpp b/src/game.cpp index d5070d0e..6ae809d2 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -4229,11 +4229,13 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, void Game::handlePlanet(VolatileRunFlags *flags) { LocalPlayer *player = client->getEnv().getLocalPlayer(); - // Quick hack: Teleport to other side of planet at planet edges if (g_settings->getBool("planet_enable")) { // Round planet circumference up to even number of blocks, value in x/z coordinates - int planet_circumference = ceil(g_settings->getU16("planet_radius") * M_PI) * BS * MAP_BLOCKSIZE * 2; + int planet_radius = g_settings->getU16("planet_radius"); + int planet_circumference = ceil(planet_radius * M_PI) * BS * MAP_BLOCKSIZE * 2; v3f playerpos = player->getPosition(); + + // Teleport to other side of planet at planet edges if (playerpos.X > planet_circumference / 2 - 0.5 * BS) playerpos.X = -(float)planet_circumference / 2 - 0.5 * BS; if (playerpos.X < -planet_circumference / 2 - 0.5 * BS) @@ -4243,8 +4245,19 @@ void Game::handlePlanet(VolatileRunFlags *flags) { if (playerpos.Z < -planet_circumference / 2 - 0.5 * BS) playerpos.Z = (float)planet_circumference / 2 - 0.5 * BS; - flags->planet_warp_changed = player->getPosition() != playerpos; + // Falling through the planet. The point on the other side is defined as + // pos.X += circumference / 2, as if the planet was a torus. + if (g_settings->getBool("planet_fallthrough_enable")) { + if (playerpos.Y < -planet_radius * MAP_BLOCKSIZE * BS) { + playerpos.Y = -planet_radius * MAP_BLOCKSIZE * BS + BS; + playerpos.X += planet_circumference / 2. * (playerpos.X < 0 ? 1 : -1); + v3f playerspeed = player->getSpeed(); + playerspeed.Y *= -1; + player->setSpeed(playerspeed); + } + } + flags->planet_warp_changed = player->getPosition() != playerpos; player->setPosition(playerpos); } }